Geeks With Blogs

News
View Szymon Kobalczyk's profile on LinkedIn

Szymon Kobalczyk's Blog A Developer's Notebook

Updated: This project now has its own page.

I use CruiseControl.NET with MSBuild for automated build of a .NET 2.0 project. You can find instructions how to setup this in Michael Swanson's Blog. Everything works fine but one thing that bothered me was that CC.NET logged raw console output from MSBuild, whereas I wanted the results as structured XML document so it can be nicely integrated into the build report and formatted with XSL. What I needed was an XML Logger for MSBuild.

I first found one written by Wilco Bauwer but didn't liked that way it logged the build events (as plain list of events losing the hierarchy of the build process) but it helped me a lot to get started. Besides the log files were really huge. This made me to write one myself. I've posted the first version working with .NET 2.0 Beta 1 to the CC.NET JIRA. In Beta 2 you can notice that console output is colored but I still haven't found any XmlLogger as part of the Framework. But the MSBuild API changed slightly (now each type of build event has different signature) so here you can download the updated version.

To use it execute following command line:

MSBuild.exe yourproject.sln /logger:Kobush.Build.Logging.XmlLogger,Kobush.MSBuild.dll;buildresult.xml

You can also add following switches to prevent any console output:

/nologo /noconsolelogger

The output verbosity level can be specified using /verbosity parameter. I tried to make it produce the same output on various levels like from default console logger.

Updated: I've included two XSL files for CC.NET Web Dashboard that can format the build results. First one (compile-msbuild.xsl) adds new section on build summary page. To use it add following line in the dashboard\plugins\buildPlugins\buildReportBuildPlugin\xslFileNames section of the dashbard.config file:

xsl\compile-msbuild.xsl

Second one (msbuild.xsl) can be used to configure additional project report plug-in. Add following line in the dashboard\plugins\buildPlugins section:

Above configuration applies to latest CC.NET 0.9 but the files can be used with earlier versions.

I hope someone would find it useful and if you have any problems or suggestions just let me know.

Posted on Friday, May 6, 2005 9:42 PM Development | Back to top


Comments on this post: XmlLogger for MSBuild

# re: XmlLogger for MSBuild
Requesting Gravatar...
I need to have build output for msBuild in CC.net, however I'm using a build.proj file and executing it via the command prompt using msBuild.ext
Can you use this with .proj files with the logger parameters? I'm doing the following and getting:

>MsBuild build.proj "/logger:Kobush.Build.Logging.XmlLogger, Kobush.MsBuild.dll;buildresult.xml"

It's stating it can't find an instance of the logger?
Left by Sandra on Jun 28, 2005 1:10 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I just tried it on .csproj file and it works fine. Did you copy the Kobush.MsBuild.dll to your working directory? Also I don't think there should be a space after a collon in the logger option.
Left by Szymon on Jun 28, 2005 1:22 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I didn't mean .csproj files, I'm using build.proj (msbuild project files) and passing it to the msbuild.exe. This .proj file has all the tasks, properties, items, etc... defined in it that is executed by msbuild.
Left by Sandra on Jun 28, 2005 2:51 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Sorry if you were mistunderstood before, I should have been clearer.
Have you used msbuild.proj files before with this type of logger?
Left by Sandra on Jun 28, 2005 3:46 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I've been using it with .sln files, .csproj files and with build files that I'v written myself. If msbuild compiles this without a logger then it shouldn't matter. Again, make sure you have the Kobush.MsBuild.dll in the same folder as your project build file and remove any spaces in the logger option. Also make sure that you have the same version of .NET framework (I compiled against Beta 2).
Left by Szymon on Jun 28, 2005 3:58 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Ok thanks, I'll check that. I'm just upgrading to CCNet 9.2 as I was using 0.7.
Left by Sandra on Jun 28, 2005 4:06 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Did you have any problems when upgrading to 0.9.2?
It's completely wrecked my build!
Left by Sandra on Jun 28, 2005 6:00 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I just finished upgrading and everything went smoothly. One thing to remember is to back up all your configuration files, because they can get overwritten. I also moved the build working directory away from the server dir and saved build state file.
Left by Szymon on Jun 29, 2005 12:15 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Could you help?
I've basically just ran the setup.exe for 0.9.2 which installed the service, ctray and webdashboard. As everything was setup previously for 0.7 I had to need to configure anything really, just insert my ccnet.config file and start the service, however I'm getting errors galour?
What was the process you took to upgrade, maybe I've missed something.
Sorry about all the questions.
Left by Sandra on Jun 29, 2005 12:18 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
There were some changes in the config file format when CCNET 9 came out. Put your mail in the URL field here so I can contact you directly.
Left by Szymon on Jun 29, 2005 1:02 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I've just sorted it, it was the config file, can you believe it! They should have put it on their website. Errors were put in the eventlog.

I'm just going to get it in a stable state and then I'll try and hookup you're logger so I can get build output to the site.
Thanks for you're help so far, no doubt I'll be intouch in a bit!
Left by Sandra on Jun 29, 2005 1:10 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
It won't work when have the following in CCNet build task for msbuild, I place it in the <buildArgs> item:
MsBuild build.proj /logger:Kobush.Build.Logging.XmlLogger, Kobush.MsBuild.dll;buildresult.xml

Do you think it will work if I place it in the actual build.proj file, under the tools.devenv task for the sln file?
Left by Sandra on Jun 29, 2005 4:57 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
In your logger, 'BuildFinishedEventArgs' is part of what namespace? Is it Microsoft.Build.Framework?
Left by Sandra on Jun 29, 2005 5:25 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Do you have to put your plugin dll in 'bin' directory of web dashboard?
Left by Lynn on Jul 05, 2005 11:11 AM

# re: XmlLogger for MSBuild
Requesting Gravatar...
On my projects I just put it in the same directory with the build scripts. But I have settled to using NAnt for main build script and exec msbuild as one of the tasks. If you are calling msbuild directly from CCNet using exec task then you can specify a working directory there. Place the dll in that directory. Or you can add full path to the dll in the logger option after colon(e.g. /logger:Kobush.Build.Logging.XmlLogger,C:\Projects\Build\Kobush.MSBuild.dll).
Left by Szymon on Jul 05, 2005 11:21 AM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Thanks for that. For the second xsl file, I've put the following in my dashboard config as the actionname, is this correct, as the description above you put it missing?

<xslReportBuildPlugin description=MsBuild Report actionName=MsBuildReport xslFileName=xslmsbuild.xsl />
Left by Lynn on Jul 05, 2005 12:01 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
You need to add quotes on the attribute values. I have it like this for the project report plug-in:

<xslReportBuildPlugin description="MSBuild Output" actionName="MSBuildOutputBuildReport" xslFileName="xsl\msbuild.xsl" />

For the build report plug-in I added this to existing section:

<buildReportBuildPlugin>
<xslFileNames>
...
<xslFile>xsl\compile-msbuild.xsl</xslFile>
...
</xslFileNames>
</buildReportBuildPlugin>
Left by Szymon on Jul 05, 2005 12:16 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
It's producing the buildresult.xml file, however when I view it in the web dashboard and select MSBuild Output i get an error stating 'Log does not contain any xml output from msbuild (use the argument:......)'???
Left by Lynn on Jul 05, 2005 4:31 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
You need to merge the buildresult.xml file into project build log. Use the merge task in the CCNet.config like this:

<merge>
<files>
<file>path\to\buildresult.xml</file>
</files>
</merge>
Left by Szymon on Jul 05, 2005 4:37 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Yes I've done that too?
Left by Lynn on Jul 05, 2005 4:56 PM

# How To: Write a custom logger for MSBuild
Requesting Gravatar...
This question came across the internal conversion alias this morning:

Is there a way to send errors...
Left by MSBuild Team Blog on Oct 10, 2005 10:28 AM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I had to modify a XmlLogger.cs method to get it to work here in the en-GB culture. Ironically I've done this by hard-coding the en-US culture into the following method.

The DateTime.Parse method defaults to the local culture, but for some reason the timestamp is written out by the LogStageStarted method in the en-US culture.

My hacked up method now reads:

private void LogStageFinished(bool succeded, DateTime timeStamp)
{
if (currentElement.Name == XmlLoggerElements.Build || Verbosity == LoggerVerbosity.Diagnostic)
{
IFormatProvider culture = new CultureInfo("en-US");
DateTime startTime = DateTime.Parse(currentElement.GetAttribute(XmlLoggerAttributes.StartTime),culture);
SetAttribute(currentElement, timeStamp - startTime, XmlLoggerAttributes.ElapsedTime);
}

SetAttribute(currentElement, succeded, XmlLoggerAttributes.Success);

if (this.currentElement.ParentNode is XmlElement)
{
XmlElement parentElement = (XmlElement)this.currentElement.ParentNode;

// don't put element's that don't contain any messages
if (!currentElement.HasChildNodes && Verbosity != LoggerVerbosity.Detailed && Verbosity != LoggerVerbosity.Diagnostic)
parentElement.RemoveChild(currentElement);

this.currentElement = parentElement;
}
}

Left by Charles Crichton on Oct 18, 2005 12:08 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Charles,
Thanks for your comment and fix. I intend to publish updated sources on ProjectDistributor as soon as I get the VS Final Release and verify everything works fine. There were also some fixes made by the CCNET team that I need to integrate back to my code.
Left by Szymon on Oct 18, 2005 12:15 PM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I think there is a bug...

private void SetAttribute(XmlElement element, object obj, string name)
{ ...

else if (t == typeof(TimeSpan))
{
// format TimeSpan to show only integral seconds
double seconds = ((TimeSpan)obj).Seconds;
TimeSpan whole = TimeSpan.FromSeconds(Math.Truncate(seconds));
element.SetAttribute(name, whole.ToString());
}
...
}

----

((TimeSpan)obj).Seconds

should be:

((TimeSpan)obj).TotalSeconds

else you will always get a value in the range [0..59]
Left by Morten Teinum on Jan 11, 2006 6:15 AM

# re: XmlLogger for MSBuild
Requesting Gravatar...
Thank you Mortan. I was planing to release the updated version for VS RTM. I should include your path, as well as few other and hopefully release it soon.
Left by Szymon on Jan 11, 2006 10:22 AM

# re: XmlLogger for MSBuild
Requesting Gravatar...
I've created separate page for this project including some usage instructions. Also the updated version was published (projectdistributor.net/Releases/Release.aspx?releaseId=298).
Left by Szymon on Jan 14, 2006 10:14 AM

Your comment:
 (will show your gravatar)


Copyright © Szymon Kobalczyk | Powered by: GeeksWithBlogs.net | Join free