通过 MSBuild 构建 Visual Studio 2015 C++ 项目 (v140) 失败 - 找不到 v140

2024-02-09

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

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

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

如果我将项目的平台工具切换到 v120,它就可以工作。

Details:

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.

UPDATE:

  • 调试 X86 中跳过了一些项目。这是故意的。
  • 该项目最初是在VS2008中创建的,然后升级到VS2013,然后升级到VS2015。
  • 此计算机上安装了两个 Visual Studio(2013 Community 和 2015 Community)。先安装2013年的,后安装2015年的。

The registry settings looks like: enter image description here

UPDATE2: 最小、完整且可验证的示例 https://stackoverflow.com/help/mcve

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

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

#include "stdafx.h"

int main()
{
    return 0;
}

我可以在 Visual Studio 中构建它,但在 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:\>

SOLVED:

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

简单的控制台应用程序在环境变量 VisualStudioVersion 更改后以及 Windows 注销、登录后立即开始工作。

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


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

您可以在标题为“VisualStudioVersion”的 MSDN 博客文章中找到有关 VisualStudioVersion 变量的更多信息Visual Studio 项目兼容性和 VisualStudioVersion http://blogs.msdn.com/b/webdev/archive/2012/08/22/visual-studio-project-compatability-and-visualstudioversion.aspx.

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

通过 MSBuild 构建 Visual Studio 2015 C++ 项目 (v140) 失败 - 找不到 v140 的相关文章

随机推荐