How to automate building a solution using MsBuild API 4.0?

Bogdan Gavril MSFT picture Bogdan Gavril MSFT · Mar 14, 2012 · Viewed 7k times · Source

I have a bunch of solutions downloaded from the Internet (codeplex etc.) and I want to build them and run a tool over the DLLs. I want to do this via automation.

It has been suggested to use MSBuild API because it will make it easy to get error information and manipulate MsBuild futher to obtain other info. Unfortunately it is hardly documented so:

  1. How do I build an .sln file (via MSBuild API 4.0) ?
  2. How do I capture the error information? (I saw an example on how to output the log to the console, but did not find smth for files)

Thanks!

Answer

Bogdan Gavril MSFT picture Bogdan Gavril MSFT · Mar 14, 2012

I found a related question on stackoverflow that provides the solution:

running msbuild programmatically

The accepted answer provides good resources:

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

Also, there is an example of log usage on msdn: http://msdn.microsoft.com/en-us/library/microsoft.build.framework.ilogger.aspx