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();
但是它抛出了以下异常:
However it's throwing the following exception:
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" version="15.1.1012"
- id="Microsoft.Build.Tasks.Core" version="15.1.1012"
- id="Microsoft.Build.Utilities.Core" version="15.1.1012"
仍然得到相同的结果.
我也尝试过像这样使用 BuildManager
:
I've also tried using the BuildManager
like this:
var buildManager = new BuildManager();
buildManager.Build(new BuildParameters(),
new BuildRequestData(new ProjectInstance(CS_PROJ_FILE),
new[] {"Build"}));
推荐答案
我安装后遇到同样的错误:
I hit the same error after I installed:
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 构建项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 Microsoft.Build API 构建项目


- 良好实践:如何重用 .csproj 和 .sln 文件来为 CI 创建 2022-01-01
- C# 中多线程网络服务器的模式 2022-01-01
- 在哪里可以找到使用中的C#/XML文档注释的好例子? 2022-01-01
- MoreLinq maxBy vs LINQ max + where 2022-01-01
- 如何用自己压缩一个 IEnumerable 2022-01-01
- WebMatrix WebSecurity PasswordSalt 2022-01-01
- 输入按键事件处理程序 2022-01-01
- Web Api 中的 Swagger .netcore 3.1,使用 swagger UI 设置日期时间格式 2022-01-01
- 带有服务/守护程序应用程序的 Microsoft Graph CSharp SDK 和 OneDrive for Business - 配额方面返回 null 2022-01-01
- C#MongoDB使用Builders查找派生对象 2022-09-04