5
votes

I have a lot of developers currently using Visual Studio 2012 and I would like to upgrade them to 2015 in two stages. First upgrade to Visual Studio 2015, then upgrade to the new MSBuild (compiler) toolset. This is important because I would like builds in Visual Studio to use the same toolset as builds in our build scripts, which are available on developer machines and used by the build servers. I would like to avoid picking a day and telling every developer to install Visual Studio 2015, and simultaneously pushing changesets to our repositories/branches to update the build scripts all at once.

From my understanding, the ToolsVersion attribute of the Project element in the project file drives the distinction between MSBuild versions. However, when building a project with ToolsVersion=4.0 in Visual Studio 2015, I receive the following messages:

Building with tools version "14.0".
Project file contains ToolsVersion="4.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.

In addition to that, I can follow the build output and see that it is in fact using the Visual Studio 2015 toolset to compile the code. I know the "4.0" toolset is not missing (I have Visual Studio 2012 installed, along with the .NET Framework versions that include that version of MSBuild), so I'm assuming either Visual Studio 2015 can't find it, or there is a "policy reason" I don't understand.

According to the MSDN page for Standard and Custom Toolset Configurations, MSBuild 12.0 (Visual Studio 2013) includes the 4.0 toolset. However I can't find any information on MSBuild 14.0 (Visual Studio 2015).

Is it possible to build in Visual Studio 2015, but use the Visual Studio 2012 toolset? If so, how? And what are the "policy reasons" mentioned in the build warning?

1

1 Answers

0
votes

Solution

Have your developers set the environment variable MSBUILDDEFAULTTOOLSVERSION to 4.0. One simple way to do this is to have them run open an elevated PowerShell prompt and run:

[Environment]::SetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION", "4.0", "Machine")

Visual Studio will need to be reopened before it will pick up this change. Once you are ready to upgrade to the new MSBuild toolset, have your developers remove that environment variable:

[Environment]::SetEnvironmentVariable("MSBUILDDEFAULTTOOLSVERSION", "4.0", "Machine")

Background

From MSDN (emphasis mine):

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.

Incidentally, to verify which MSBuild toolsets are available on a machine and where they are located, you can just open up PowerShell and run:

dir HKLM:\Software\Microsoft\MSBuild\ToolsVersions