<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
You can modify the value of MSBuildToolsPath
by defining a custom Toolset. For more information, see Standard and custom Toolset configurations.
When you build a solution on the command line and specify a ToolsVersion
for msbuild.exe, all projects and their project-to-project dependencies are built according to that ToolsVersion
, even if each project in the solution specifies its own ToolsVersion
. To define the ToolsVersion
value on a per project basis, see Overriding ToolsVersion settings.
The ToolsVersion
attribute is also used for project migration. For example, if you open a Visual Studio 2008 project in Visual Studio 2010, the project file is updated to include ToolsVersion="4.0". If you then try to open that project in Visual Studio 2008, it doesn't recognize the upgraded ToolsVersion
and therefore builds the project as though the attribute was still set to 3.5.
Visual Studio 2010 and Visual Studio 2012 use a ToolsVersion of 4.0. Visual Studio 2013 uses a ToolsVersion of 12.0. Visual Studio 2015 uses ToolsVersion 14.0, and Visual Studio 2017 uses ToolsVersion 15.0. In many cases, you can open the project in multiple versions of Visual Studio without modification. Visual Studio always uses the correct Toolset, but you will be notified if the version used does not match the version in the project file. In almost all cases, this warning is benign as the Toolsets are compatible in most cases.
Sub-toolsets, which are described later in this topic, allow MSBuild to automatically switch which set of tools to use based on the context in which the build is being run. For example, MSBuild uses a newer set of tools when it's run in Visual Studio 2012 than when it's run in Visual Studio 2010, without your having to explicitly change the project file.
Implement a Toolset by selecting the paths of the various tools, targets, and tasks that make up the Toolset. The tools in the Toolset that MSBuild defines come from the following sources:
The .NET Framework folder.
Additional managed tools.
The managed tools include ResGen.exe and TlbImp.exe.
MSBuild provides two ways to access the Toolset:
By using Toolset properties
By using ToolLocationHelper methods
Toolset properties specify the paths of the tools. Starting in Visual Studio 2017, MSBuild no longer has a fixed location. By default, it is located in the MSBuild\15.0\Bin folder relative to the Visual Studio installation location. In earlier versions, MSBuild uses the value of the ToolsVersion
attribute in the project file to locate the corresponding registry key, and then uses the information in the registry key to set the Toolset properties. For example, if ToolsVersion
has the value 12.0
, then MSBuild sets the Toolset properties according to this registry key: HKLM\Software\Microsoft\MSBuild\ToolsVersions\12.0.
These are Toolset properties:
MSBuildToolsPath
specifies the path of the MSBuild binaries.
SDK40ToolsPath
specifies the path of additional managed tools for MSBuild 4.x (which could be 4.0 or 4.5).
SDK35ToolsPath
specifies the path of additional managed tools for MSBuild 3.5.
Alternately, you can determine the Toolset programmatically by calling the methods of the ToolLocationHelper class. The class includes these methods:
GetPathToDotNetFramework returns the path of the .NET Framework folder.
GetPathToDotNetFrameworkFile returns the path of a file in the .NET Framework folder.
GetPathToDotNetFrameworkSdk returns the path of the managed tools folder.
GetPathToDotNetFrameworkSdkFile returns the path of a file, which is typically located in the managed tools folder.
GetPathToBuildTools returns the path of the build tools.
See also
Standard and custom Toolset configurations
Multitargeting