Click here to Skip to main content
15,867,488 members
Articles / Programming Languages / XML
Tip/Trick

An exe to generate CodeMetrics Summary report in HTML form

Rate me:
Please Sign up or sign in to vote.
4.67/5 (2 votes)
18 Jul 2012CPOL2 min read 18.7K   485   5   3
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
<?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:

C#
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)


Written By
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
Bugmetrics summary class Pin
Member 1505945630-Jan-21 18:27
Member 1505945630-Jan-21 18:27 
GeneralMy vote of 5 Pin
Ashutosh Phoujdar21-Sep-15 21:35
Ashutosh Phoujdar21-Sep-15 21:35 
QuestionDefault.css missing in attached downloads Pin
Ashutosh Phoujdar21-Sep-15 21:35
Ashutosh Phoujdar21-Sep-15 21:35 
Hi dreamzlife,

Many thanks for sharing this nice utility.

I have downloaded and ran the tool and it generated the reports nicely as expected, however I am not able to locate the default.css file in binary package.

I would be great help, if you can share it !!!

Thanks,
ashutosh
ashufouzdar@outlook.com

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.