Ludek Vodicka
Ludek Vodicka

Reputation: 1730

MSBuild doesn't work in VS2017 for VS2015 (v140) toolkit

I have installed VS2017 with v141 (2017) and v140(2015) toolkits.

Unfortunately, MSBUILD command line doesn't work with v140 toolkit.

When I use "C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat" I'm getting 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, you may upgrade to the current Visual Studio tools by selecting the Project menu or right-click the solution, and then selecting "Upgrade Solution...". [q:\ExternalLibraries\cryptopp-5.6.5-2015\cryptlib.vcxproj]

But when I open the same project/solution in VS IDE, I see that project is already configured as 2015 project and I'm able to compile it without problems with v140 toolkit.

Also worth to note that NMAKE command line tools work without any problems. Only MSBUILD returns this strange error.

Is there anything else I have to do to be able to use VS140 toolkit in VS2017 in command line?

Edit:

Based on detailed VS log in IDE it seems that IDE silently ignore tools version. This is error message from log

Project file contains ToolsVersion="12.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="15.0". For more information, please see http://go.microsoft.com/fwlink/?LinkId=293424.

So I tried to upgrade solution to latest version and than manually set v140 toolset instead of v141.

But now MSBuilds return following error:

"q:\ExternalLibraries\cryptopp-5.6.5-2015\cryptest.sln" (Rebuild target) (1) -> "q:\ExternalLibraries\cryptopp-5.6.5-2015\cryptest.vcxproj.metaproj" (Rebuild target) (2) -> "q:\ExternalLibraries\cryptopp-5.6.5-2015\cryptlib.vcxproj" (Rebuild target) (3) -> q:\ExternalLibraries\cryptopp-5.6.5-2015\cryptlib.vcxproj(44,3): error MSB4019: The imported project "q:\Microsoft.Cp p.Default.props" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

Mentioned import element really exists in vcxproj with following values

<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />

So it seems that VCTargetsPath is not filled and because of that MSBuild can't find it. Any advice?

PS: When I run the same project from VS2017 command prompt, compilation works without any issues.

Upvotes: 2

Views: 3097

Answers (1)

Chuck Walbourn
Chuck Walbourn

Reputation: 41117

C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat is the VS 2015 version which won't support v141.

VS 2017 now supports side-by-side installs of itself with different editions, and it no longer shares a global MSBuild rule set which is what VS 2015 and earlier did. You need to use the VS 2017 version of the tools/variables to get it to support both v140 and v141.

For VS 2017 Enterprise, it's C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\VC\Auxiliary\Build\vcvars32.bat.

For Community it would be C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\VC\Auxiliary\Build\vcvars32.bat

To use v140 with the command line, you need to use some additional parameters:

vcvarsall.bat x86 -vcvars_ver=14.0

Upvotes: 4

Related Questions