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:
Thanks!
To build a specific target of a specific project in a solution. At the command line, type MSBuild.exe <SolutionName>. sln , where <SolutionName> corresponds to the file name of the solution that contains the target that you want to execute.
MSBuild includes common tasks that you can modify to suit your requirements. Examples are Copy, which copies files, MakeDir, which creates directories, and Csc, which compiles Visual C# source code files.
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.
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
Maybe I'm missing something, but why does it have to be the MSBuild API for a simple task like that?
Just from what you've written in the question, I see no need to use the API just to build a solution and capture the output in a text file.
You can use the MSBuild command line tool for this.
Building a solution with MSBuild is as simple as that:
%windir%\Microsoft.net\Framework\v4.0.30319\msbuild.exe MySolution.sln
To capture the output in a text file, you just need to add this:
(example copied from the link)
/l:FileLogger,Microsoft.Build;logfile=MyLog.log
So the final statement looks like this:
%windir%\Microsoft.net\Framework\v4.0.30319\msbuild.exe MySolution.sln /l:FileLogger,Microsoft.Build;logfile=MyLog.log
This will build the solution and save the output of MSBuild in a text file named MyLog.log
in the current directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With