我正在尝试使用Microsoft.Build中的类构建一个项目。
守则是:
var project = new ProjectInstance(CS_PROJ_FILE);
project.Build();但是,它会引发以下异常:
Microsoft.Build.Shared.InternalErrorException occurred
HResult=0x80131500
Message=MSB0001: Internal MSBuild Error: Type information for Microsoft.Build.Utilities.ToolLocationHelper was present in the whitelist cache as Microsoft.Build.Utilities.ToolLocationHelper, Microsoft.Build.Utilities.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a but the type could not be loaded. unexpectedly null
Source=Microsoft.Build我尝试将以下内容添加到包中(包括在net452和net7项目中):
结果还是一样的。
我也尝试过像这样使用BuildManager:
var buildManager = new BuildManager();
buildManager.Build(new BuildParameters(),
new BuildRequestData(new ProjectInstance(CS_PROJ_FILE),
new[] {"Build"}));发布于 2017-05-30 10:54:55
安装后,我也遇到了相同的错误:
Install-Package Microsoft.Build -Version 15.1.1012但后来我安装了:
Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012一切都开始运作了。
有点困惑..。
"dasMulli“在以下位置指出了这个堆栈溢出问题:
发布于 2018-04-24 02:29:55
显然有一种新的方法来解决这个问题,正如这里和这里所描述的那样。
以下是对我起作用的东西:
Microsoft.Build.dll、Microsoft.Build.Framework.dll、Microsoft.Build.Tasks.Core.dll和Microsoft.Build.Utilities.Core.dll (即所有Microsoft.Build .dll文件)。Microsoft.Build NuGet包。Microsoft.Build.Locator NuGet包。这修复了OP列出的异常,避免了大量编译器无法解析所有引用的错误消息。
编辑:更多信息在这里:https://gist.github.com/DustinCampbell/32cd69d04ea1c08a16ae5c4cd21dd3a3
发布于 2019-10-25 06:12:27
Micrsoft提供了一个很好的链接这里
诀窍确实是使用nuget块,并指定ExcludeAssets=runtime来告诉NuGet,程序集仅在构建时才需要,不应该复制到输出目录。
https://stackoverflow.com/questions/44249320
复制相似问题