Click here to Skip to main content
Click here to Skip to main content

An exe to generate CodeMetrics Summary report in HTML form

, 18 Jul 2012
Rate this:
Please Sign up or sign in to vote.
A simple way to parse multiple CodeMetrics XML data and generate a summary report.

Introduction

In a big project maintainability is a big challenge. Visual Studio now has an embedded way to generate code metrics report. When there are >10 binaries present it is always welcome to  have a summary report. Such a report can be easily integrated with the daily build and published in different build dashborads, e.g., Jenkins/Hudson.

Background  

Details of CodeMetrics itself is a big chapter itself. The following link from MSDN has the basics explained: http://msdn.microsoft.com/en-us/library/bb385914.aspx

Using metrics.exe (available with PowerTools) we can easily generate XML reports.

Refer to this nice article: http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx

The sole purpose of this article is to generate a short summary report from a generated XML file. Also to convert the individual XML to HTML. For that purpose I have used XSD also from Skinner's blog.

Refer to: http://blogs.msdn.com/b/camerons/archive/2011/02/20/code-metrics-reporting-and-xslt-debugging.aspx

Using the Binary 

Mention the input folder name under Folder  key in app.config. Ensure all the generated XML is stored there. Run the exe. The HTML reports will be generated under the  HTMLReports folder.

Using the code 

In the application we can easily specify the values for a different MI index range. We can mention the input and output folders. All this are driven through the  app.config. The input directory can be passed as a parameter also.

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key ="Low" value="20"/>
    <add key ="Medium" value="50"/>
    <add key ="High" value="80"/>
    <add key ="Folder" value="CodeMetricsReport"/>
    <add key ="OutputXML" value="MetricsSummary.xml"/>
    <add key ="OutFolder" value="HTMLReports"/>
  </appSettings>
</configuration>

CodeMetricsReportGenerator  is the primary class. Also it converts the individual reports to HTML. The AnalysisCodeMetrics method analyses all the XML files and stores the info in memory.

GenerateMISummaryReport generates the summary report. For this it uses the  MetricsSummary.XSL file.

Using XML to XSLT transform, we generate the HTML output:

XslTransform myXslTransform;
myXslTransform = new XslTransform();
myXslTransform.Load("MetricsSummary.xsl");
myXslTransform.Transform(outputXML, outputfolder + "\\" + output);

The summary report looks like this:

Points of Interest

The whole idea is to have a track of maintainability index for a large project and showcase easily the data in easily understandable HTML format.

The next step is to create an MSBuild project which can perform all the tasks like code coverage, code analysis, code metrics, MSTest, and generate a report.

Pease vote if you find this helpful.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

dreamzlife

United States United States
No Biography provided

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web02 | 2.8.140827.1 | Last Updated 18 Jul 2012
Article Copyright 2012 by dreamzlife
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid