Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Build project with Microsoft.Build API

I'm trying to build a project using the classes in Microsoft.Build.

The code is:

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

I've tried adding the following to the packages (both in a net452 and a net7 project):

  • id="Microsoft.Build" version="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"

Still get the same result.

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"}));
like image 776
BanksySan Avatar asked May 29 '17 19:05

BanksySan


People also ask

How do I create a build property in Microsoft?

MSBuild lets you set properties on the command line by using the -property (or -p) switch. These global property values override property values that are set in the project file. This includes environment properties, but does not include reserved properties, which cannot be changed.

What is Microsoft Build Engine?

The Microsoft Build Engine is a platform for building applications. This engine, which is also known as MSBuild, provides an XML schema for a project file that controls how the build platform processes and builds software.

Is MSBuild a build tool?

MSBuild is a build tool that helps automate the process of creating a software product, including compiling the source code, packaging, testing, deployment and creating documentations. With MSBuild, it is possible to build Visual Studio projects and solutions without the Visual Studio IDE installed.


1 Answers

I hit the same error after I installed:

Install-Package Microsoft.Build -Version 15.1.1012

But then I installed:

Install-Package Microsoft.Build.Utilities.Core -Version 15.1.1012

And things started working.

A little confusing...

I was pointed to this stackoverflow question by "dasMulli" at:

https://github.com/Microsoft/msbuild/issues/1889

like image 158
Derek Avatar answered Sep 20 '22 21:09

Derek