简体   繁体   中英

VS2015: How to build using MSBuild 12.0?

I have VS2015 (MSBuild 14.0) and VS2013 (MSBuild 12.0) installed. There reason for this is that I have a project I could only build using MSBuild 12.0 . I've already been trough here , here , and here . I changed the project file to specify MSBuild 12.0, but I get the following error:

Project file contains ToolsVersion="12.0". This toolset may be unknown or missing, in which case you may be able to resolve this by installing the appropriate version of MSBuild, or the build may have been forced to a particular ToolsVersion for policy reasons. Treating the project as if it had ToolsVersion="14.0". For more information, please see http://go.microsoft.com/fwlink/?LinkId=293424 .

I know the tool set is not missing, it is installed here: C:\\Program Files (x86)\\MSBuild\\12.0 .

I was hoping it would be something straight forward as changing ToolsVersion=12.0 in my .csproj file.

Additionally, I work with a team, so ideally I'm looking for the least invasive solution. I prefer not to change registry values and such.

Any help is much appreciated.

We could not use Tools Version 12 in visual studio 2015 directly. MSDN says:

"Starting in Visual Studio 2013, the MSBuild Toolset version is the same as the Visual Studio version number. MSBuild defaults to this Toolset within Visual Studio and on the command line, regardless of the ToolSet version specified in project file. This behavior can be overridden by using the /ToolsVersion flag. For more information, see Overriding ToolsVersion Settings ."

We can override the ToolsVersion Settings of Projects and Solutions by using command prompt:

msbuild.exe someproj.proj /tv:12.0

Besides, Guy Bolton King provided a Visual Studio extension to achieve it. Here is the the extension repository project on GitHub.

Set-toolsversion-extension that temporarily sets the environment variable MSBUILDDEFAULTTOOLSVERSION for the duration of a build; the value to be used is read from a file .toolsversion in the same directory as the .sln file. The psake script reads the same .toolsversion file and passes the value to the /tv switch.

Please build the extension project and install the SetToolsVersion.vsix to visual studio.

Note that : Thanks @mbadawi23 for reminding that cleaned the solution, closed VS and opened it again after installed the extension and also need to add the .toolsversion.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM