If you want to run Code Metrics for your Visual Studio solution, you will need to download the appropriate version of Code Metrics Power Tool corresponding to your Visual Studio version.
For Visual Studio 2015, you can download the Code Metrics Power Tool from here: https://www.microsoft.com/en-us/download/details.aspx?id=48213
If you need to integrate the calculation of Code Metrics into your automated build process (such as Jetbrains TeamCity), then you can learn how to use Code Metrics from the command line here: http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx
If you need to make the XML results viewable, then you will probably need a set of XSLT and CSS files to transform the XML into HTML, then you will want to take a look at this article: https://blogs.msdn.microsoft.com/camerons/2011/02/20/code-metrics-reporting-and-xslt-debugging/
Unfortunately, the links to the XSLT and CSS are broken!
I was able to dig up a version of the MetricsResultsTransform.xslt file from another site which I am providing for your reference below:
However, I was not able to find the Default.css file, so this functionality is still missing from the XSLT transformation.
If you think Microsoft should ship a default set of XSLT and CSS files with the Code Metrics PowerTool, you can vote for this UserVoice item here: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/15832576-ship-default-xslt-and-css-files-with-the-code-metr
For Visual Studio 2015, you can download the Code Metrics Power Tool from here: https://www.microsoft.com/en-us/download/details.aspx?id=48213
If you need to integrate the calculation of Code Metrics into your automated build process (such as Jetbrains TeamCity), then you can learn how to use Code Metrics from the command line here: http://blogs.msdn.com/b/camerons/archive/2011/01/28/code-metrics-from-the-command-line.aspx
If you need to make the XML results viewable, then you will probably need a set of XSLT and CSS files to transform the XML into HTML, then you will want to take a look at this article: https://blogs.msdn.microsoft.com/camerons/2011/02/20/code-metrics-reporting-and-xslt-debugging/
Unfortunately, the links to the XSLT and CSS are broken!
I was able to dig up a version of the MetricsResultsTransform.xslt file from another site which I am providing for your reference below:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" | |
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl" | |
> | |
<xsl:output method="html" indent="yes"/> | |
<xsl:template match="/"> | |
<html> | |
<head> | |
<link rel = "stylesheet" type="text/css" href="Default.css" /> | |
</head> | |
<body> | |
<h1>Complexity Metrics</h1> | |
<xsl:call-template name="TargetTOC" /> | |
<xsl:apply-templates select="//Targets/Target" /> | |
</body> | |
</html> | |
</xsl:template> | |
<!-- | |
Create the table of contents for all the Targets found | |
in the xml file | |
--> | |
<xsl:template name="TargetTOC"> | |
<div class="TOCEntry"> | |
<h2>Modules</h2> | |
<xsl:for-each select="//Target"> | |
<a class="TOCEntry"> | |
<xsl:attribute name="href"> | |
#<xsl:value-of select="./Modules/Module/@Name"/> | |
</xsl:attribute> | |
<xsl:value-of select="./Modules/Module/@Name"/> | |
</a> | |
</xsl:for-each> | |
</div> | |
</xsl:template> | |
<!-- | |
Create the table of contents for all the namespaces found | |
in the module / target | |
--> | |
<xsl:template name="NamespaceTOC"> | |
<div class="TOCEntry"> | |
<h2>Namespaces</h2> | |
<xsl:for-each select=".//Namespace"> | |
<xsl:call-template name="TOCEntryByName" /> | |
</xsl:for-each> | |
</div> | |
</xsl:template> | |
<!-- | |
Create the table of contents for all the types in | |
the namespace | |
--> | |
<xsl:template name="TypeTOC"> | |
<div class="TOCEntry"> | |
<h2>Types</h2> | |
<xsl:for-each select=".//Type"> | |
<xsl:call-template name="TOCEntryByName" /> | |
</xsl:for-each> | |
</div> | |
</xsl:template> | |
<!-- | |
Create the table of contents for all the members of the | |
type | |
--> | |
<xsl:template name="MemberTOC"> | |
<div class="TOCEntry"> | |
<h2>Members</h2> | |
<xsl:for-each select=".//Member"> | |
<xsl:call-template name="TOCEntryByName" /> | |
</xsl:for-each> | |
</div> | |
</xsl:template> | |
<!-- | |
A helper XSLT function that builds the anchor tag | |
of any element with a 'Name' attribute | |
--> | |
<xsl:template name="TOCEntryByName"> | |
<a class="TOCEntry"> | |
<xsl:attribute name="href"> | |
#<xsl:value-of select="@Name"/> | |
</xsl:attribute> | |
<xsl:value-of select="@Name"/> | |
</a> | |
</xsl:template> | |
<!-- Template for the Target element. All elements in the metrics | |
results file is contained in this element --> | |
<xsl:template match="Target"> | |
<xsl:apply-templates select="./Modules/Module" /> | |
</xsl:template> | |
<xsl:template match="Module"> | |
<h2> | |
<xsl:call-template name="BookMark" /> | |
</h2> | |
<div class="Level1"> | |
<table class="ModuleDetails"> | |
<tr> | |
<td class="Label">Full Path:</td> | |
<td> | |
<xsl:value-of select="../../@Name"/> | |
</td> | |
</tr> | |
<tr> | |
<td class="Label">Assembly Verion:</td> | |
<td> | |
<xsl:value-of select="@AssemblyVersion"/> | |
</td> | |
</tr> | |
<tr> | |
<td class="Label">File Version:</td> | |
<td> | |
<xsl:value-of select="@FileVersion"/> | |
</td> | |
</tr> | |
</table> | |
<xsl:apply-templates select="Metrics" /> | |
<xsl:call-template name="NamespaceTOC" /> | |
<xsl:apply-templates select="./Namespaces/Namespace" /> | |
</div> | |
</xsl:template> | |
<xsl:template match="Metrics"> | |
<div> | |
<table class="Metrics"> | |
<xsl:for-each select="./Metric"> | |
<tr> | |
<td class="Label"><xsl:value-of select="@Name"/>:</td> | |
<td> | |
<xsl:value-of select="@Value"/> | |
</td> | |
</tr> | |
</xsl:for-each> | |
</table> | |
</div> | |
</xsl:template> | |
<xsl:template match="Namespace"> | |
<div class="Level1"> | |
<h2> | |
Namespace: <xsl:call-template name="BookMark" /> | |
</h2> | |
<xsl:apply-templates select="Metrics" /> | |
<div class="Level1"> | |
<xsl:call-template name="TypeTOC" /> | |
<xsl:apply-templates select="./Types/Type"/> | |
</div> | |
</div> | |
</xsl:template> | |
<xsl:template name="BookMark"> | |
<a> | |
<xsl:attribute name="name"> | |
<xsl:value-of select="@Name"/> | |
</xsl:attribute> | |
<xsl:value-of select="@Name"/> | |
</a> | |
</xsl:template> | |
<xsl:template match="Type"> | |
<div> | |
<h2> | |
Type: <xsl:call-template name="BookMark" /> | |
</h2> | |
<xsl:apply-templates select="Metrics" /> | |
<div class="Level1"> | |
<xsl:call-template name="MemberTOC"/> | |
<xsl:apply-templates select="./Members/Member" /> | |
</div> | |
</div> | |
</xsl:template> | |
<xsl:template match="Member"> | |
<div> | |
<h4> | |
<xsl:call-template name="BookMark" /> | |
</h4> | |
<table class="MemberDetails"> | |
<tr> | |
<td class="Label">File:</td> | |
<td> | |
<xsl:value-of select="@File"/> | |
</td> | |
</tr> | |
<tr> | |
<td class="Label">Line:</td> | |
<td> | |
<xsl:value-of select="@Line"/> | |
</td> | |
</tr> | |
</table> | |
<xsl:apply-templates select="Metrics" /> | |
</div> | |
</xsl:template> | |
</xsl:stylesheet> |
If you think Microsoft should ship a default set of XSLT and CSS files with the Code Metrics PowerTool, you can vote for this UserVoice item here: https://visualstudio.uservoice.com/forums/121579-visual-studio-2015/suggestions/15832576-ship-default-xslt-and-css-files-with-the-code-metr
Thanks, I followed the same steps as you did in the past and this post was the very last thing I found :O :)
ReplyDelete