3

我刚刚将一个项目从 Visual C++ 2012 升级到 Visual C++ 2017,我从 MSBuild 中遇到了构建失败:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Cpp.Current.targets(64,5):错误 MSB4062:无法加载“SetEnv”任务从程序集 C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\VC\VCTargets\Microsoft.Build.CppTasks.Common.dll。无法加载文件或程序集“Microsoft.Build.Utilities.Core, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a”或其依赖项之一。该系统找不到指定的文件。确认声明正确,程序集及其所有依赖项都可用,并且任务包含实现 Microsoft.Build.Framework.ITask 的公共类。[C:\src\my-project.vcxproj]

Fusion 日志显示了不好的情况:

*** Assembly Binder Log Entry  (2/12/2018 @ 1:44:29 PM) ***

The operation failed.
Bind result: hr = 0x80070002. The system cannot find the file specified.

Assembly manager loaded from:  C:\Windows\Microsoft.NET\Framework\v4.0.30319\clr.dll
Running under executable  C:\windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe
--- A detailed error log follows. 

=== Pre-bind state information ===
LOG: DisplayName = Microsoft.Build.Utilities.Core, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
 (Fully-specified)
LOG: Appbase = file:///C:/windows/Microsoft.NET/Framework/v4.0.30319/
LOG: Initial PrivatePath = NULL
LOG: Dynamic Base = NULL
LOG: Cache Base = NULL
LOG: AppName = msbuild.exe
Calling assembly : Microsoft.Build.CPPTasks.Common, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a.
===
LOG: This bind starts in LoadFrom load context.
WRN: Native image will not be probed in LoadFrom context. Native image will only be probed in default load context, like with Assembly.Load().
LOG: Using application configuration file: C:\windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.
LOG: Post-policy reference: Microsoft.Build.Utilities.Core, Version=15.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a
LOG: GAC Lookup was unsuccessful.
LOG: Attempting download of new URL file:///C:/windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Build.Utilities.Core.DLL.
LOG: Attempting download of new URL file:///C:/windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Build.Utilities.Core/Microsoft.Build.Utilities.Core.DLL.
LOG: Attempting download of new URL file:///C:/windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Build.Utilities.Core.EXE.
LOG: Attempting download of new URL file:///C:/windows/Microsoft.NET/Framework/v4.0.30319/Microsoft.Build.Utilities.Core/Microsoft.Build.Utilities.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/VC/VCTargets/Microsoft.Build.Utilities.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/VC/VCTargets/Microsoft.Build.Utilities.Core/Microsoft.Build.Utilities.Core.DLL.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/VC/VCTargets/Microsoft.Build.Utilities.Core.EXE.
LOG: Attempting download of new URL file:///C:/Program Files (x86)/Microsoft Visual Studio/2017/Professional/Common7/IDE/VC/VCTargets/Microsoft.Build.Utilities.Core/Microsoft.Build.Utilities.Core.EXE.
LOG: All probing URLs attempted and failed.

刚刚在Visual Studio Community上发布了这个,但在另一个几乎相同的错误报告中,由于我无法理解的原因,他们将其关闭为“不是错误”。我希望 StackOverflow 会更有帮助。:)

4

2 回答 2

7

Microsoft.Build.CPPTasks.Common 找不到 Microsoft.Build.Tasks.Core

看来您正在使用 .NET 框架中的旧 MSBuild.exe。将项目从 VS2012 升级到 VS2017 后,您应该从以下位置使用 MSBuild.exe:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MSBuild.exe

那是因为MSBuild 现在是 Visual Studio 的一部分!

从 Visual Studio 2013 开始,2013 版本的 MSBuild 将作为 Visual Studio 的一部分而不是 .NET Framework 提供。这种转变使我们能够更快地发展 MSBuild。

希望这可以帮助。

于 2018-02-13T05:33:04.033 回答
0

您必须编辑此目录中的文件:

C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets

称为:

Microsoft.Cpp.Clang.targets

将第 17 行编辑为:

<UsingTask TaskName="ClangCompile" AssemblyFile="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\Common7\IDE\VC\VCTargets\Microsoft.Build.CppTasks.Common.dll"/>

如果这确实会产生您可能需要安装正确的 MSBuild 的其他问题,请注意。

于 2019-07-20T21:05:13.947 回答