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 CPOL
Rate this:
Please Sign up or sign in to vote.
A simple way to parse multiple CodeMetrics XML data and generate a summary report.


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.


Details of CodeMetrics itself is a big chapter itself. The following link from MSDN has the basics explained:

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

Refer to this nice article:

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:

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" ?>
    <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"/>

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.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.


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


About the Author


United States United States
No Biography provided

Comments and Discussions

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