MSBuild构建Visual Studio 2015 C ++项目(v140)失败-无法找到v140 [英] Building Visual Studio 2015 C++ project (v140) by MSBuild Failed - v140 cannot be found

查看:104
本文介绍了MSBuild构建Visual Studio 2015 C ++项目(v140)失败-无法找到v140的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我并排安装了Visual Studio 2013和2015.我刚刚将合并的解决方案(C#,C ++,C ++/CLI)升级到了2015年,并将Platform Toolset设置为v140.

I have Visual Studio 2013 and 2015 installed side by side. I have just upgraded the combined solution (C#, C++, C++/CLI) to 2015 and set Platform Toolset to v140.

Visual Studio的构建工作正常,但是无法从MSBuild进行编译.我使用MSBuild 14,MSBuild抱怨找不到v140,但这是无稽之谈,因为在计算机"c:\ Program Files(x86)\ MSBuild \ Microsoft.Cpp \ v4.0 \ V140"中安装了v140.

The build from Visual Studio works fine, but it cannot be compiled from MSBuild. I use MSBuild 14 and MSBuild complains that is unable to find v140, but it is nonsense, because v140 is installed on the computer in "c:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140".

无法完成有关升级解决方案的建议,因为解决方案已经升级,并且解决方案上下文菜单中没有此类项目.

The advice about upgrading the solution cannot be done, because the solution is already upgraded and there is no such item in solution context menu.

如果我将项目的平台工具切换到v120,则可以正常工作.

If I switch Platform tools of the project to v120, it works.

详细信息:

c:\git\hewerMaster>"c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild.exe"  c:\git
\hewerMaster\Hewer.sln /property:Configuration=Debug /property:Platform=x86
Microsoft (R) Build Engine version 14.0.23107.0
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
Build started 9/12/2015 4:00:25 PM.
Project "c:\git\hewerMaster\Hewer.sln" on node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|x86".
ValidateProjects:
  The project "HewerDotNetWrapper" is not selected for building in solution con
  figuration "Debug|x86".
  The project "VisualHewer" is not selected for building in solution configurat
  ion "Debug|x86".
  The project "UnitTestWrapper" is not selected for building in solution config
  uration "Debug|x86".
  The project "ParamsFormatConverter" is not selected for building in solution
  configuration "Debug|x86".
  The project "UnitTestGenerator" is not selected for building in solution conf
  iguration "Debug|x86".
  The project "HewerUnitTestDotNet" is not selected for building in solution co
  nfiguration "Debug|x86".
Project "c:\git\hewerMaster\Hewer.sln" (1) is building "c:\git\hewerMaster\Hewe
rRedirect\HewerRedirect.csproj" (2) on node 1 (default targets).
CoreCompile:
Skipping target "CoreCompile" because all output files are up-to-date with resp
ect to the input files.
_CopyAppConfigFile:
Skipping target "_CopyAppConfigFile" because all output files are up-to-date wi
th respect to the input files.
CopyFilesToOutputDirectory:
  HewerRedirect -> c:\git\hewerMaster\anyCPU\Debug\pbrain-hewer.exe
Done Building Project "c:\git\hewerMaster\HewerRedirect\HewerRedirect.csproj" (
default targets).

Project "c:\git\hewerMaster\Hewer.sln" (1) is building "c:\git\hewerMaster\Hewe
r\Hewer.vcxproj" (3) on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.t
argets(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 bu
ild tools.  Alternatively, you may upgrade to the current Visual Studio tools b
y selecting the Project menu or right-click the solution, and then selecting "U
pgrade Solution...". [c:\git\hewerMaster\Hewer\Hewer.vcxproj]
Done Building Project "c:\git\hewerMaster\Hewer\Hewer.vcxproj" (default targets
) -- FAILED.

Done Building Project "c:\git\hewerMaster\Hewer.sln" (default targets) -- FAILE
D.


Build FAILED.

更新:

  • 从Debug X86跳过了一些项目.这是故意的.
  • 该项目最初是在VS2008中创建的,然后升级到VS2013,然后升级到VS2015.
  • 此计算机上安装了两个Visual Studio(2013社区和2015社区).首先安装2013,之后安装2015.

注册表设置如下:

UPDATE2:最小,完整和可验证的示例

我在Visual Studio 2015中创建了空的C ++控制台应用程序:

I have created empty C++ Console Application in Visual Studio 2015:

https://dl.dropboxusercontent.com/u/53387801/ConsoleApplication_v140.zip

#include "stdafx.h"

int main()
{
    return 0;
}

我可以在Visual Studio中构建它,但是在MSBuild中也遇到相同的问题:

I can build it in Visual Studio, but I face the same issue in MSBuild:

c:\>"c:\Program Files (x86)\MSBuild\14.0\Bin\MSBuild" "C:\temp\vs2015_simplest\C
onsoleApplication1\consoleApplication1.sln"
Microsoft (R) Build Engine version 14.0.23107.0
Copyright (C) Microsoft Corporation. All rights reserved.

Building the projects in this solution one at a time. To enable parallel build,
please add the "/m" switch.
Build started 9/16/2015 10:16:20 AM.
Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" o
n node 1 (default targets).
ValidateSolutionConfiguration:
  Building solution configuration "Debug|x64".
Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" (
1) is building "C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplication1
\ConsoleApplication1.vcxproj" (2) on node 1 (default targets).
C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V120\Microsoft.Cpp.Platform.t
argets(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 bu
ild tools.  Alternatively, you may upgrade to the current Visual Studio tools b
y selecting the Project menu or right-click the solution, and then selecting "U
pgrade Solution...". [C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplic
ation1\ConsoleApplication1.vcxproj]
Done Building Project "C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleAppli
cation1\ConsoleApplication1.vcxproj" (default targets) -- FAILED.

Done Building Project "C:\temp\vs2015_simplest\ConsoleApplication1\consoleAppli
cation1.sln" (default targets) -- FAILED.


Build FAILED.

"C:\temp\vs2015_simplest\ConsoleApplication1\consoleApplication1.sln" (default
target) (1) ->
"C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleApplication1\ConsoleApplica
tion1.vcxproj" (default target) (2) ->
(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 = 'v1
40') 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...". [C:\temp\vs2015_simplest\ConsoleApplication1\ConsoleAppl
ication1\ConsoleApplication1.vcxproj]

    0 Warning(s)
    1 Error(s)

Time Elapsed 00:00:00.14

c:\>

已解决:

环境变量VisualStudioVersion设置为12.0,而不是14.0 .将值更改为14.0解决了该问题.

Environment variable VisualStudioVersion was set to 12.0 instead of 14.0 Changing the value to 14.0 solved the issue.

环境变量VisualStudioVersion更改并且Windows注销,登录后,简单的控制台应用程序立即开始工作.

The simple console application started to work immediately after the Environment variable VisualStudioVersion changed and after windows logout, login.

更改环境变量VisualStudioVersion后仍无法构建原始项目.重新定位解决方案上下文菜单出现在Visual Studio 2015中.因此,我重新定位了解决方案.重新定向解决方案后,仍然无法编译解决方案(找不到v140).最后,我将平台工具集从 v140(未安装)更改为 Visual Studio 2015(v140).现在,该解决方案也可以从Visual Studio和MSBuild中进行编译.

The original project still couldn't be build after changing environment variable VisualStudioVersion. A retarget solution context menu appeared in Visual Studio 2015. So I retarget the solution. After retargeting the solution still couldn't be compiled (v140 not found). Finally I changed the platform toolset from v140 (not installed) to Visual Studio 2015 (v140). Now the solution can be compiled from Visual Studio and MSBuild as well.

推荐答案

您的问题是将环境变量 VisualStudioVersion 设置为 12.0 .这告诉MSBuild使用Visual Studio 2013(V120)工具,该工具不支持Visual Studio 2015(V140)生成工具.如果您取消设置此环境变量,或者将/p:VisualStudioVersion=14.0 选项传递给MSBuild您的项目,则应进行构建.(或者至少克服了这个错误).

Your problem is that you set the environment variable VisualStudioVersion to 12.0. This tells MSBuild to use the Visual Studio 2013 (V120) tools, which don't support the Visual Studio 2015 (V140) build tools. If you unset this environment variable, or pass the /p:VisualStudioVersion=14.0 option to MSBuild your project, should build. (Or at least get past this error).

您可以在标题为 查看全文

相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆