Ban*_*San 10 .net c# msbuild build
我正在尝试使用Microsoft.Build中的类来构建项目.
代码是:
var project = new ProjectInstance(CS_PROJ_FILE);
project.Build();
Run Code Online (Sandbox Code Playgroud)
然而,它抛出以下异常:
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
Run Code Online (Sandbox Code Playgroud)
我已经尝试将以下内容添加到包中(在net452和net7项目中):
仍然得到相同的结果.
我也试过用BuildManager这样的:
var buildManager = new BuildManager();
buildManager.Build(new BuildParameters(),
new BuildRequestData(new ProjectInstance(CS_PROJ_FILE),
new[] {"Build"}));
Run Code Online (Sandbox Code Playgroud)
Der*_*rek 12
我安装后遇到了同样的错误:
Install-Package Microsoft.Build -Version 15.1.1012
Run Code Online (Sandbox Code Playgroud)
但后来我安装了:
Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012
Run Code Online (Sandbox Code Playgroud)
事情开始奏效了.
有点混乱......
我被"dasMulli"指向了这个stackoverflow问题:
https://github.com/Microsoft/msbuild/issues/1889
以下是对我有用的内容:
我删除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 包。
我在我的程序中添加了以下代码:
// This needed after upgrading to Roslyn revision 34025, see these two links:
// https://github.com/dotnet/roslyn/issues/26029
// /sf/answers/3492043411/
MSBuildLocator.RegisterDefaults();
Run Code Online (Sandbox Code Playgroud)这修复了 OP 列出的异常,并避免了大量关于无法解析所有引用的编译器错误消息。
编辑:更多信息在这里:https : //gist.github.com/DustinCampbell/32cd69d04ea1c08a16ae5c4cd21dd3a3
| 归档时间: |
|
| 查看次数: |
2064 次 |
| 最近记录: |