Mike Wise
Mike Wise

Reputation: 22847

Msbuild not using specified toolset for Visual C++ project

I have a machine with side-by-side VS2015 and VS2013 installed, and am trying to get something built using the VS2013 toolset (v120). However inspite of an explicit override in the project file, it is trying to use v140.

C:\transfer\MathLib\testSse>msbuild Sse.vcxproj
Microsoft (R) Build Engine version 12.0.40629.0
[Microsoft .NET Framework, version 4.0.30319.42000]
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 23-Mar-17 12:35:07.
Project "C:\transfer\MathLib\testSse\Sse.vcxproj" on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build t
ools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 bui
ld tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-cli
ck the solution, and then selecting "Upgrade Solution...". [C:\transfer\MathLib\testSse\Sse.vcxproj]
Done Building Project "C:\transfer\MathLib\testSse\Sse.vcxproj" (default targets) -- FAILED.


Build FAILED.

"C:\transfer\MathLib\testSse\Sse.vcxproj" (default target) (1) ->
(PlatformPrepareForBuild target) ->
  C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build
 tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, please install v140 b
uild tools.  Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-c
lick the solution, and then selecting "Upgrade Solution...". [C:\transfer\MathLib\testSse\Sse.vcxpro
j]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.16

C:\transfer\MathLib\testSse>notepad Sse.vcxproj

Here is the relevent excerpt from the project file:

  <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
    <PlatformToolset>v120</PlatformToolset>
  </PropertyGroup>
  <PropertyGroup Label="Configuration" Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
    <PlatformToolset>v120</PlatformToolset>
  </PropertyGroup>

I can override this with this command:

msbuild Sse.vcxproj /p:PlatformTooset=v120

And then it compiles, but that doesn't really fix the problem since I have a lot of these in a large Visual Studio solution, and I need all of them to use that parameter. Unless I could put that msbuild override parameter in the solution somehow.

But still, what is causing msbuild to use another toolset that I is not mentioned anywhere?

One possibility is that I installed VS2013 after VS2015 - which is a bit unusual I suppose. Could that be the issue?

Upvotes: 1

Views: 785

Answers (1)

Leo Liu
Leo Liu

Reputation: 76928

AndIf you create a project with Visual Studio 2015 and get it built using the VS2013 toolset (v120). You need change the Platform Toolset to Visual Studio 2013 (v120) on the Property Pages.

When you using MSBuild command to build the project, we need to change the PlatformToolset to V120 in the .vcxproj file. <PlatformToolset>v120</PlatformToolset>. And the default platform is Win32 when we create a Visual C++ project:

enter image description here

I have noticed that the PlatformToolset has been set v120 only for x64 in the relevant excerpt from the project file. In this case, if you build the project with default platform Win32 by MSBuild command, you will get that error:"error MSB8020: The build tools for v140 (Platform Toolset = 'v140') cannot be found."

To resolve this issue, you need to change the PlatformToolset to v120 for Win32 in the .vcxproj file:

Besides,

One possibility is that I installed VS2013 after VS2015 - which is a bit unusual I suppose. Could that be the issue?

I also installed VS2013 after VS2015 to reproduce your issue, but after correct the value of PlatformToolset for Win32, MSBuild build could be successfully without any error. So this issue does not related to the installation order, do not need to worry about it.

Hope this can help you.

Upvotes: 1

Related Questions