How to automate solution building using MsBuild API 4.0?

I have a bunch of solutions downloaded from the Internet (codeplex, etc.), and I want to create them and run the tool for the DLL. I want to do this with automation.

It has been proposed to use the MSBuild API because it will make it easier to get error information and manipulate the MsBuild futher to get other information. Unfortunately, this is hardly documented like this:

  • How to create a .sln file (via MSBuild API 4.0)?
  • How do I get error information? (I saw an example of how to output the log to the console, but did not find smth for the files)

Thanks!

+4
source share
3 answers

I found a related stackoverflow question that provides a solution:

soft start msbuild

The accepted answer provides good resources:

http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/ec95c513-f972-45ad-b108-5fcfd27f39bc/ Logging Creating Messages Using MSBuild 4.0: http://www.go4answers.com /Example/building-solution-programatically-vs-5395.aspx

In addition, there is an example of using the log in msdn: http://msdn.microsoft.com/en-us/library/microsoft.build.framework.ilogger.aspx

+4
source

Maybe I missed something, but why is it needed for the MSBuild API for a simple task?

Just from what you wrote in the question, I don’t see the need to use the API only to create a solution and capture output in a text file.
You can use the MSBuild command-line tool for this.

Building a solution using MSBuild is just as easy:

%windir%\Microsoft.net\Framework\v4.0.30319\msbuild.exe MySolution.sln 

To capture the output in a text file , you just need to add the following:
(example copied from the link)

 /l:FileLogger,Microsoft.Build;logfile=MyLog.log 

So, the last statement is as follows:

 %windir%\Microsoft.net\Framework\v4.0.30319\msbuild.exe MySolution.sln /l:FileLogger,Microsoft.Build;logfile=MyLog.log 

This will create a solution and save the output of MSBuild in a text file named MyLog.log in the current directory.

+3
source

Nothing you describe requires using the MSBuild API. Using the MS Build API is worth it if you want to extend the build process for custom build tasks, but it is not useful if you just want to automate your builds. The API is very well documented. I like the MSDN documentation here. MSBuild API

To answer your questions directly: 1) MSBuild does not understand solution files. This is a visual studio concept. MSBuild will β€œrun” the solution file if it is created from the command line, but it does this by creating the msbuild file from the solution file. You will get the same effect by directly managing your project project files.

2) As already mentioned, my Christian, you can do this with a registrar. Here's the documentation: Build Logger

If you want to automate your builds, use an installed build automation environment such as Jenkins or TeamCity.

+1
source

Source: https://habr.com/ru/post/1401269/


All Articles