Click here to Skip to main content
15,352,321 members
Articles / Programming Languages / XML
Posted 18 Jul 2012

Tagged as


5 bookmarked

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

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

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.