Code Metrics, Reporting, and XSLT Debugging

In my last post, I announced a new power tool that allows you to analyze your managed assemblies to determine various complexity metrics. The output of the power tool is a fairly simple XML file, so in this post, I wanted to show you how simple it is to turn that simple xml file into a report you could actually use.

I’ve included a simple XSLT file as well as a CSS file that you can use to bootstrap any efforts you have in this regard.

All you need to do is drop the XSLT and CSS file into the same directory as your xml results after running the power tool, and then be sure to add one line to that xml file, like so:

 <?xml-stylesheet type="text/xsl" href="MetricResultsTransform.xslt" ?>

right after the xml declaration statement at the top of the file.

Once you’ve done that, you’ll get a simple report that looks something like this:

image

NOTE: If you aren’t familiar with Visual Studio’s ability to debug XSLT transforms, I highly recommend checking it out. All you need to do is open an XSLT file in VS, set a break point anywhere in the XSLT file, then hit Alt-F5. VS will then allow you to step through the various transformations, seeing the result of the transformation in the doc well. Very cool stuff if you find yourself having to write lots of XSLTs.

Enjoy!

Cameron

Comments

  • Anonymous
    April 23, 2011
    Nice article!Is there any way to have code metrics results reported on TFS so the results can be viewed via Team Web Access as part of the build report?Thanks

  • Anonymous
    April 23, 2011
    No, there isn't currently a way to do that unfortunately.

  • Anonymous
    August 28, 2011
    Is there a way to automate the injection of the stylesheet transformation from msbuild

  • Anonymous
    August 29, 2011
    The comment has been removed

  • Anonymous
    May 14, 2012
    Drop the XSLT and CSS file into the same directory as your xml results (result.xml) after running the power tool.Add (right after top) <?xml-stylesheet type="text/xsl" href="MetricResultsTransform.xslt" ?>Once you’ve done that, you’ll get a simple report ? How ? Where ?Are we missing some steps above ?

  • Anonymous
    May 14, 2012
    If you open the xml file with Internet Explorer, you should see the formatted report.