web-dev-qa-db-ja.com

MSBuildによるVisual Studio 2015 C ++プロジェクト(v140)のビルドに失敗しました-v140が見つかりません

Visual Studio 2013と2015を並べてインストールしています。組み合わせたソリューション(C#、C++、C++/CLI)を2015にアップグレードし、プラットフォームツールセットをv140に設定しました。

Visual Studioからのビルドは正常に機能しますが、MSBuildからコンパイルすることはできません。 MSBuild 14を使用し、v140が見つからないというMSBuildの苦情がありますが、v140はコンピューターの "c:\ Program Files(x86)\ MSBuild\Microsoft.Cpp\v4.0\V140"にインストールされているため、意味がありません。

ソリューションは既にアップグレードされており、ソリューションコンテキストメニューにはそのような項目がないため、ソリューションのアップグレードに関するアドバイスは実行できません。

プロジェクトのプラットフォームツールをv120に切り替えると、機能します。

詳細:

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.

更新:

  • デバッグX86からスキップされているプロジェクトがあります。これは意図的なものです。
  • プロジェクトは元々VS2008で作成され、VS2013にアップグレードされ、VS2015にアップグレードされました。
  • このコンピューターには2つのVisual Studioがインストールされています(2013コミュニティと2015コミュニティ)。 2013年が最初にインストールされ、2015年が後にインストールされました。

レジストリ設定は次のようになります。 enter image description here

MS Build registry settings

UPDATE2:最小、完全、検証可能な例

Visual Studio 2015で空のC++コンソールアプリケーションを作成しました。

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

解決しよう:

環境変数VisualStudioVersionが14.0ではなく12.0に設定されました値を14.0に変更すると問題が解決しました。

単純なコンソールアプリケーションは、環境変数VisualStudioVersionが変更され、Windowsがログアウトしてログインした直後に動作し始めました。

環境変数VisualStudioVersionを変更した後でも、元のプロジェクトをビルドできませんでした。ソリューションのターゲット変更コンテキストメニューがVisual Studio 2015に登場しました。そのため、ソリューションのターゲットを変更しました。ターゲットを変更した後でも、ソリューションをコンパイルできませんでした(v140が見つかりません)。最後に、プラットフォームツールセットをv140(not installed)からVisual Studio 2015(v140)。これで、ソリューションをVisual StudioとMSBuildからコンパイルできます。

10
Tomas Kubes

問題は、環境変数VisualStudioVersion12.0に設定することです。これにより、MSBuildはVisual Studio 2013(V120)ツールを使用するように指示されますが、Visual Studio 2015(V140)ビルドツールはサポートされません。この環境変数を設定解除するか、プロジェクトのMSBuildに/p:VisualStudioVersion=14.0オプションを渡すと、ビルドするはずです。 (または、少なくともこのエラーを回避してください)。

Visual Studioプロジェクトの互換性とVisualStudioVersion というタイトルのMSDNブログエントリでVisualStudioVersion変数の詳細を確認できます。

11
Ross Ridge

1つの解決策は、システムで使用可能なプラットフォームツールセットを簡単に変更できることです。それからそれはうまく構築します。

2
Abc