Code Metrics Viewer 2015 is available for download

I am a man of few words… an new extension package is out now that integrates the Code Metrics Power Tool for Visual Studio 2015 into Visual Studio 2015 (requires Update 1). It provides the exact same functionality as it´s predecessor targeting Visual Studio 2013, except to a minor fix required to make themes work properly, since the way the IDE stores information about the current selected theme had slightly changed…

Updated: Roslyn Metrics extension

Roslyn seemed to be a good choice…

The Roslyn compiler API has evolved over time… the latest pre-release available on Nuget performs way better than the CTP published almost two years ago, so I decided to continue working on my metrics calculator that is based on Microsoft´s new compiler API. In addition to the initially implemented metrics, like maintainability index, cyclomatic complexity, depth of inheritance, class coupling and lines of code, I added a bunch of other metrics. For instance, lack of cohesion of methods (a metric that can be used to find poorly cohesive types), number of overloads of a method, number of lines of comments and some other low-hanging fruits likes counters for fields, method parameters, methods, types and so on…

The Roslyn metrics extension does not analyse compiled assemblies, instead syntax- and semantic models are used to aggregate information right from the source code. In my opinion, this has some signifact advantages, because calculated metric results are closer to the code typed by the developer (since the code is not optimized by the compiler). It´s also possible to calculate metric results even on projects which do do not compile (for instance, due to missing third-party assemblies or any other kind of build dependency).

Calculating metrics on non-optimized (as typed) code also allows definition of metrics which put code readability more into focus. For instance, I could imagine a metric that finds all variable declarations in a method, which could be moved closer to their usage, which is something that drastically improves readability and stability, because narrowing a variables scope can help to prevent situations where a variable has not been set to a valid instance or value. The purpose of the lines of comments metric (as already implemented) is obvious, I think… comments are adding noise to the code, which has a poor impact on readability (apart from that, comments are usually not more than a pack of lies). Code containing comments might also hold potential for refactoring.

Anything else? Yes. Now, the metrics calculator is also available as a standalone application, so it´s possible to use the tool in a CI build environment. The download can be found at:

Published: Code Metrics Viewer 2012

I published updates of all my Visual Studio Gallery contributions. Actually, there´s no new functionality in there, just minor changes, a few bug-fixes and updated references to third-party libraries. I changed the names of the tools a bit; “Code Metrics Viewer” has been renamed to “Code Metrics Viewer 2010” and the pre-release of “Code Metrics Viewer 2” is now named “Roslyn Metrics“, which makes more sense since I created the Code Metrics Viewer 2012 extension that integrates the Code Metrics Power Tool 11.0 into Visual Studio 2012.

As I wrote in my last post, the Code Metrics Power Tool 11.0 does not have a setup… but don´t worry (-: After you´ve installed the Code Metrics Viewer 2012 extension, just open the Options dialog, navigate to Code Metrics, than Tools – and click the “Download and Install…”-button. This will download the Power Tool from: and extract it to the local FxCop-directory. If you´re interested in how the setup routine works, you can take a look at the code that I published on github…

Code Metrics Viewer 2012 Options Dialog

Code Metrics Power Tool 11.0

Some weeks ago, Microsoft released the Code Metrics Power Tool 11.0 that works together with the latest FxCop binaries of Visual Studio 2012. What a surprise… I did not exptect that they would come up with a new version of the tool, due to the fact that the code metrics analysis feature is now also available in Visual Studio Professional (of course I know it´s intended to be used in an automated build environment). Even though I implemented my own metrics calculator based on the Roslyn September 2012 CTP, I will integrate the Power Tool into the Code Metrics Viewer 2… thinking about to move the experimental Roslyn stuff into a separate package. Will see…

For god´s sake! I would like to know why the Power Tool does not have a user-friendly setup? It is compressed into a self-extracting cabinet file. In my opinion this would be okay, if the package would also contain all dependencies which are required to run the application. This would allow to install it to a directory free of choice. But no, the Metrics.exe binary is tightly coupled to Visual Studio binaries and must be copied to the FxCop directory within the Visual Studio installation folder (at least this is mentioned by the installation instructions on the download page). So, before I do the integration, I need to think about a setup util…

I wrote some sample code that can be used to build a simple setup application:

Update, 2013/09/20: The Code Metrics Viewer 2012 extension is now available at:

Transform reports to CSV using XSLT

The following XSLT stylesheet is a fairly simple transformation allowing to convert XML metric reports to CSV format (the columns do not have a fixed length, instead a “,” char is used as the delimiter). The CSV columns have the following order: Module, Namespace, Type, Member, Maintainability Index, Cyclomatic Complexity, Class Coupling, Depth of Inheritance, Lines of Code.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="" xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

  <xsl:output method="text" indent="no" encoding="utf-8" />
  <xsl:strip-space elements="*" />

  <xsl:template match="/">

  <xsl:template name="MetricValues">
    <xsl:variable name="v1" select="./Metric[@Name = 'MaintainabilityIndex']/@Value" />
    <xsl:variable name="v2" select="./Metric[@Name = 'CyclomaticComplexity']/@Value" />
    <xsl:variable name="v3" select="./Metric[@Name = 'ClassCoupling']/@Value" />
    <xsl:variable name="v4" select="./Metric[@Name = 'DepthOfInheritance']/@Value" />
    <xsl:variable name="v5" select="./Metric[@Name = 'LinesOfCode']/@Value" />
    <xsl:variable name="s" select="concat($v1, ',', $v2, ',', $v3, ',', $v4, ',', $v5)" />
    <xsl:value-of select="$s" />

  <xsl:template match="Metrics">
    <xsl:variable name="moduleName" select="ancestor::Module/@Name" />
    <xsl:variable name="namespaceName" select="ancestor::Namespace/@Name" />
    <xsl:variable name="typeName" select="ancestor::Type/@Name" />
    <xsl:variable name="memberName" select="ancestor::Member/@Name" />
    <xsl:variable name="s" select="concat($moduleName, ',', $namespaceName, ',', $typeName, ',', $memberName, ',')" />
    <xsl:if test="$moduleName != ''">
      <xsl:value-of select="$s" />
    <xsl:call-template name="MetricValues" />

New release: Version 1.6.0

I migrated the WPF user interface (that I had implemented for Code Metrics Viewer 2) to the Visual Studio 2010 extension in order to address some user interface issues which have been requested by users many times. Now, the grid allows to scroll horizontally, allows to change the position of grid columns and icons have been added to namespace-, type- and member- nodes. I also removed the modal progress dialog – and added an indeterminate progress indicator to the tool window instead. The toolbar is now a native Visual Studio toolbar that uses the blue theme…


Code Metrics Viewer 2 CTP

I published a pre-release version of the Code Metrics Viewer 2 extension targeting Visual Studio 2012. It´s the continuation of my first contribution, but it works completly different. The first version was just a user-interface that integrated the Code Metrics Power-Tool 10.0 into the development environment, but the new version brings it´s own calculation functionality – and instead of analyzing IL it acts on source code. The current release supports metric calculation for C#-projects, but functionality supporting Visual Basic is on schedule.

The extension is dependent on the Microsoft “Roslyn” CTP (September 2012, v1.2), which need to be downloaded and installed separatly. Because I wasn´t sure, if I am allowed to distribute the Roslyn binaries, I decided to exclude them from the extension package and defined a dependency to the Roslyn Components instead. The Extension Manager will show the following dialog to you, if the required package dependency is missing.


The download can be found at the Visual Studio Developer Center: or on NuGet: If the components will be removed after installing the extension, calculation of metric results isn´t possible and the following error message will be shown: “The calculation of metric results has failed. Couldn´t find the Roslyn CTP components.”