Download XmlLogger files from MSDN Code Galery
Using the XmlLogger
To use additional logger with MSBuild you use the /logger switch. It requires the fully qualified class name of the logger (including namespace) and assembly name separated with coma. You can also pass additional parameters to the logger after a semicolon. My logger takes only one parameter, and it is the output filename. If this parameter is opmitted output will be directed to console.
To use the XmlLogger when building your project execute following command line:
MSBuild.exe yourproject /logger:Kobush.Build.Logging.XmlLogger,Kobush.MSBuild.dll;buildresult.xml
Where yourproject can be a Visual Studio solution file (.sln), a language specific project file (.csproj or .vbproj) or a custom build file.
You can also add following switches to stop all output to the console:
The output verbosity level can be specified using /verbosity parameter (short form /v). The available verbosity levels are: q[uiet], m[inimal], n[ormal], d[etailed], and diag[nostic]. I tried to make my logger produce the same output on various levels as the default console logger.
Using the XmlLogger with CruiseControl.NET
CruiseControl.NET is an automated continuous integration server, implemented using the Microsoft .NET Framework. In another words it's a server that monitors your source repository and upon detecting any changes runs the build script and can perform additional tests to ensure the code is integrated correctly.
Starting from 1.0 RC1 version CC.NET adds direct support for building MSBuild projects with addition of the <msbuild /> task. For instructions on how to use MSBuild with earlier versions see Michael Swanson's blog. Here is an example of using the new task:
<buildArgs>/nologo /noconsolelogger /p:Configuration=Debug /v:diag</buildArgs>
The important part here is to specify the correct working directory for your project and to place the logger assembly in that directory. By default the <msbuild /> task will instruct the logger to output results to file called msbuild-output.xml and will automatically include the contents of this file in your build results.
Using the XmlLogger with NAnt
Personally I don't invoke MSBuild directly from CC.NET and instead have a NAnt build file that executes additional tasks (like generating version information to shared AssemblyInfo.cs file and packaging the build artifacts into a distributable package) before and after compiling my Visual Studio solution.
To invoke MSBuild from NAnt you should use the <exec /> task. Here is the full example:
<arg line="yourproject" />
<arg line="/logger:Kobush.Build.Logging.XmlLogger,Kobush.Build.dll;msbuild-output.xml" />
Then in CC.NET the project is executed using the <nant /> task. This time the MSBuild results are written to separate file so you need to add a <merge /> publisher to include the contents of this file in your build resutls.
Displaying build results with XSL stylesheets
I've included two XSL stylesheets for CC.NET Web Dashboard that can format the msbuild results. The compile-msbuild.xsl creates additonal summary section on the build report page, and the msbuild.xsl is used to configure additonal link in left sidebar showing full formatted output from the msbuild log.
To use these files put them in the xsl subfolder of CCNET web dashboard and add following lines (bold) in your dashbard.config file:
<xslReportBuildPlugin description="MSBuild Output" actionName="MSBuildOutputBuildReport"
The first version working with .NET 2.0 Beta 1 was created for my internal use, but later I posted it to the CC.NET JIRA. In Beta 2 you can notice that console output was colored but I still haven't found any XmlLogger as part of the MSBuild framework. In that version MSBuild API changed slightly (now each type of build event has different signature) so I published updated version on this blog. This is the version that is distributed with CCNET.
Although the same code works also with the final version of .NET 2.0, I took the opportunity to clear things a bit. The major change is that now I write directly to XmlTextWriter instead of using XmlDocument. This allows me to write output imadiettly as it comes, so now you can observe the progress of your build by watching as the file grows. And if anything goes wrong and MSBuild just stops you at least have some partial log of that. Besides it should be less memory consuming. This required a slight change to the XML format, as now the build duration is written in separate element. The XSL files were updated to reflect this change. Here are other minor fixes:
- Fixed: Rounding error when loging TimeSpans (thanks to Morten Teinum)
- Fixed: DateTime.Parse error in non en-US cultures (thanks to Charles Crichton)