使用Microsoft.Build API构建项目 [英] Build project with Microsoft.Build API
本文介绍了使用Microsoft.Build API构建项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用Microsoft.Build中的类来构建项目.
I'm trying to build a project using the classes in 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项目中):
I've tried adding the following to the packages (both in a net452 and a net7 project):
- id ="Microsoft.Build"版本="15.1.1012"
- id ="Microsoft.Build.Framework" version ="15.1.1012"
- id ="Microsoft.Build.Runtime"版本="15.1.1012"
- id ="Microsoft.Build.Tasks.Core" version ="15.1.1012"
- id ="Microsoft.Build.Utilities.Core" version ="15.1.1012"
仍然得到相同的结果.
我也尝试过使用BuildManager
这样:
var buildManager = new BuildManager();
buildManager.Build(new BuildParameters(),
new BuildRequestData(new ProjectInstance(CS_PROJ_FILE),
new[] {"Build"}));
推荐答案
安装后出现相同错误:
Install-Package Microsoft.Build -Version 15.1.1012
但是后来我安装了:
Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012
事情开始起作用.
有点困惑...
"dasMulli"向我指出了这个stackoverflow问题:
I was pointed to this stackoverflow question by "dasMulli" at:
https://github.com/Microsoft/msbuild/issues/1889
这篇关于使用Microsoft.Build API构建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文