Building few projects fail with MSBuild

2019-08-20 08:43发布

问题:

All other C# project files are building with MSBuild scripts. But, few C++ related projects are failing with the below error -

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets(44,5): error MSB8020: The builds tools for v140 (Platform Toolset = 'v140') cannot be found. To build using the v140 build tools, either click the Project menu or right-click the solution, and then select "Update VC++ Projects...". Install v140 to build using the v140 build tools.

I am getting the above error when I try to build the project using command prompt and the same error is getting when trying to build using Jenkins. How should we fix this issue?

回答1:

Solution 1) By creating one System Environment variable - VCTargetsPath with value - C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140, solved building the projects using command prompt on the build server.

But the above solution is not working when trying to build using Jenkins. The below solution resolved the issue.

Solution 2) Changed the build scripts to pass this parameter - /p:VCTargetsPath="C:\Program Files\MSBuild\Microsoft.Cpp\v4.0\V140"



回答2:

What’s your vs version? The C++ project you want to build seems to come from VS2015.

If you are vs2013 or earlier,we can install build tools 2015 to try to solve this issue.

Note: According to error message, the projects come from vs2015 and sometimes it may cause compatibility issues when we compile projects from higher vs versions. So I prefer to suggest you to update vs to vs2015.

In addition: Right-click on the project name=>properties=>general=>platform toolset

, then you can find the toolset versions you have, and make sure v140 have installed successfully.