我正在尝试使用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)