Thursday, February 2, 2012

Trying to get .Net Metrics Computed and Displayed with Jenkins

I'm helping a .Net team stand up Jenkins as their CI server. The build steps we have so far are building a solution and running fxCop against the debug build. Using the Jenkins Violations Plugin, which supports fxCop, we can display a nice trend chart and have hot links to drill down and see the violations in context.

My next goal was to run metrics that my team agreed on, specifically Cyclomatic Complexity and Coupling. I was hopeful because Visual Studio 2010 can already compute them. But I found out that Visual Studio's code metrics can't be called on the command line. 

Fortunately, I found Visual Studio Code Metrics PowerTool 10.0 for that purpose. There's lots of information already out about using it: Jeff Bramwell has a blog post about the PowerTool and Cameron Skinner wrote one about it.

Unfortunately, the Violations Plugin doesn't support the xml output, and the PowerTool doesn't have an option to output to HTML. Fortunately, though, Skinner also wrote a post that provides an xslt and a .css file that will turn the results into HTML.

So my next step was to make a build step that runs a command-line tool to apply the transform. I couldn’t figure out or find enough documentation on msxsl.exe, but I found this CodeProject project and it works. (Anyhow, it would only take a few lines to write your own in C# because you can use calls from MSXML.)

Now I need to figure out how to use the HTML report in Jenkins. I'll investigate the Jenkins HTML Publisher Plugin.


  1. Would love to see a writeup on how you put all of this together. I am looking to do the same thing, and with limited time, am discouraged there are so many steps to tie it all together.

  2. it's great!
    any xml parser c# for results Code Metrics PowerTool 10.0 ?

  3. A year late, but I'm just now looking to do the same thing. I want Jenkins as my CI but also want to fully leverage the suite of tools in VS2012: Tests, Code Coverage, StyleCop, FxCop, Code Analysis, and Code Metrics

  4. I have moved to another project, so I don't have any new information on this. I'd love to hear about what any of you learn!

  5. Do you have acopy of the XSLT and CSS, the original authors website links are not working. Thanks

  6. Sorry I don't have the files anymore. Maybe you can ask Skinner: