Msbuild not using specified toolset for Visual C++ project - visual-studio

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?

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:
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.

Related

VS 2017 .NET Standard Class Library build error when trigger from TFS (VSTS)

My sln is built in VS2017 and contains several .Net Standard class library dll. Build always works successfully in my local machine/virtual machine, with VS UI or just use devenv.com via command-line.
But, when I use TFS to create build task, error about InternalVisibleTo shows.
When I use MSBuild,
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\msbuild.exe" "C:\WorkArea\xxxxx\_work\1\s\xxxxx\Main\Source\xxxx.sln" /nologo /nr:false /t:"Clean" /dl:CentralLogger,"C:\WorkArea\xxxxx\tasks\MSBuild\1.0.55\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll";"RootDetailId=30268741-631d-4ac8-b4d2-d5b2774b61e7|SolutionDir=C:\WorkArea\xxxxx\_work\1\s\xxxx\Main\Source"*ForwardingLogger,"C:\WorkArea\xxxxx\tasks\MSBuild\1.0.55\ps_modules\MSBuildHelpers\Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" /p:platform="Any CPU" /p:configuration="Debug" /p:_MSDeployUserAgent="TFS_6e1df8d0-1a29-425d-803c-d70779d0c76a_build_3175_345868"
it has the error:
When I use devenv.com,
"C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\Common7\IDE\devenv.com" "C:\WorkArea\xxxxxx\_work\1\s\xxxxx\Main\Source\xxxxxx.sln" /build "debug"
it has the error:
Is it a known issue or bug of Current Visual Studio 2017 (version 15.2 - 26430.6)? What's wrong with the AssemlyInfo? What's wrong with the TFS build?
You need to restore NuGet packages before attempting the build to resolve references to the reference assemblies that provide you the core types.
You can do this using msbuild /t:Restore (TFS/VSTS: use msbuild task) or nuget.exe restore (use a nuget.exe >= 4.0.0).
There must be some issue within the latest Visual Studio 2017. They, the Microsoft, change the project file structure of .Net Core / standard a lot from 2017 RC to current one.

Upgrading a solution from Visual Studio 2010 to 2013 with command-line

I'm building many Visual Studio projects (.sln solutions files) from command-line with:
call "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"
for /r %%X in (/*.sln) do (
msbuild %%X /p:configuration=release /p:platform=win32 /nologo /noconsolelogger /fileLogger /v:quiet /flp:logfile=build_errors.log;errorsonly;append
)
Unfortunately, they all have been created with MSVS2010. Thus I get errors:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for Visual Studio 2010 (Platform Toolset = 'v100') cannot be found. To build using the v100 build tools, please install Visual Studio 2010 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...".
As I have 20 or 30 .sln files, I don't want to open each one and Upgrade solution, etc. (which I even didn't find exactly as mentioned here!).
Is there a command-line solution to upgrade all of them to MSVS2013 ?
You can upgrade solution and all of its project files through devenv /upgrade command. (devenv.exe is in the VS installation path (..\Common7\IDE).
devenv SolutionFile | ProjectFile /upgrade
To build solution/project without upgrade, you can specify Toolset argument (/tv).
msbuild %%X /p:configuration=release /p:platform=win32 /tv:12.0
If this is the only problem you can retarget the projects to use the VS2013 toolset instead of the one in VS2010. You can write a simple script in a language of your choice (or even do it manually) that iterates over all of your project files and replaces the value of PlatformToolset property to the <PlatformToolset>Visual Studio 2013 (v120)</PlatformToolset>. Alternatively, you can download and install the VS2010 build tools from the SDK - https://www.microsoft.com/en-us/download/details.aspx?id=8279

Visual Studio 2015 - Clang version not found when building from command line

I have a Xamarin-based solution in Visual Studio 2015. One of the projects is an Android native shared library containing C++ code.
When I build the solution from within VS 2015 IDE, everything works as expected. However, when I try to build the solution from the command line I get an error.
The build command is:
msbuild mytest.sln /p:Configuration=Release /p:Platform=ARM /t:Rebuild
The error I get is:
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.targets(64,5): error MSB8020: The build tools for Clang_3_8 (Platform Toolset = 'Clang_3_8') cannot be found. To build using the Clang_3_8 build tools, please install Clang_3_8 build tools. Alternatively, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...".
My Visual Studio 2015 has all the updates applied. Wondering if anyone knows what the problem could be. Is it a path problem? Regards.
Turned out it is a path problem. Make sure to use the developer command prompt link under Program Files-->Visual Studio 2015->Visual Studio Tools. This batch file sets up proper paths, including the one for clang.

Build with sdk 7.1 on VS2015

I have Visual Studio 2015 installed, and I need to compile a specific project with Visual C++ 2010 compiler, which is included in SDK 7.1.
I want to use 2010 compiler within VS2015, without install VS2010.
So, I installed it (the SDK), and "Visual Studio 2010 (v100)", "Windows7.1SDK" options appear under "Platform Toolset" property in the project properties.
But, when I try to build the project, I get those errors:
With "Windows7.1SDK" -
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\Microsoft.Cpp.x64.Targets(146,5): error : Required file "" is missing.
and with "Visual Studio 2010 (v100)" -
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Microsoft.CppBuild.targets(297,5): warning MSB8003: Could not find WindowsSDKDir variable from the registry. TargetFrameworkVersion or PlatformToolset may be set to an invalid version number.
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\Platforms\x64\Microsoft.Cpp.x64.Targets(146,5): error : Required file "" is missing.
Can't figure out what the problem is..
I had the same issue for 2 weeks and just found a workaround that might help :
Without modifying anything to my VS2010 projects (not changing the toolset in the vcxproj), I use the command line build tools MSBuild tools with the toolset specified as a switch as found here Building C++ project on a PC with Windows SDK 7.1 but without VS2010
msbuild /p:PateformToolset=Windows7.1SDK project.vcxproj
(In my case, the corresponding msbuild is in the folder C:\Windows\Microsoft.NET\Framework\v4.0.30319)
If Msbuild throws an error telling its missing mspdb100.dll, you may need to add %PROGRAMFILES(X86)%\Microsoft Visual Studio 10.0\Common7\IDE\ to your %PATH% env var.
Finally, you may have some files missing like ammintrin.h (especially if like me you try to compile old InDesign plugins) even after installing the visual c++ updates.
The only (and ugly) workaround I found in my case that does not involve installing VS2010 (the common answer of MS) is to copy the missing includes from the %PROGRAMFILES(X86)%\Microsoft Visual Studio 14.0\VC\include folder to the %PROGRAMFILES(X86)%\Microsoft Visual Studio 10.0\VC\include one.
Voila ! Hope this helps

MSBuild failing to find assembly following upgrade to VS2015

We have a build script which uses MSBuild to build our solution. It has worked fine for VS2013, but it has broken since we installed VS2015 and upgraded. Initially, it failed with this error:
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 build tools. Alternatively, yo
u may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgra
de Solution...". [C:\Users\user\Documents\GitHub[snipped]Api.vcxproj]
So it was failing to build a C++ project since is seemed to default to using version 12 of MSBuild, even though it was a VS2015 project. So I added:
/tv:14.0
To the invocation of MSBuild to force it to use the right tools version. Now it fails with this:
C:\Program Files (x86)\MSBuild\Microsoft\VisualStudio\v14.0\CodeAnalysis\Microsoft.CodeAnalysis.targets(219,5): error MSB4175: The ta
sk factory "CodeTaskFactory" could not be loaded from the assembly "C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.v12
.0.dll". Could not load file or assembly 'file:///C:\Program Files (x86)\MSBuild\14.0\bin\Microsoft.Build.Tasks.v12.0.dll' or one of
its dependencies. The system cannot find the file specified. [C:\Users\user\Documents\GitHub[snip].Api.vcxproj]
Now it's looking for a v12 assembly in the v14 folder. How do I fix this? I can't see any obvious place to make this change.
Note: The C++ project itself might be a red herring, the solution is mostly C# and this might just be the place where it loads in the tasks.

Resources