Announcing the new Code Metrics feature for Visual Studio ‘Orcas’! Available in Visual Studio Team Developer and Team Suite, this new feature allows users to generate code metrics for projects and solutions and displays the results in the Code Metrics Results tool window:

As you can see above, this feature currently calculates five different metrics; Maintainability Index, Cyclomatic Complexity, Depth of Inheritance, Class Coupling, and Lines of Code. All metrics are averaged at the type, namespace, and assembly levels with the exception of Class Coupling. The Class Coupling metric displays the total number of distinct types referenced at the method and type levels rather than the total number of type references. This is why above, the ProgramLibrary type’s class coupling is 83 instead of 103.

Users will are able to sort the results in the window by column. For example, above the results are sorted by the Maintainability Index column. Note that the proper hierarchy is maintained after sorting.

Users can also filter the results from a particular metric for values between a specified minimum and maximum value. As you can see in below the results of filtering out any results with a Maintainability Index greater than twenty are displayed. (The Library project is still displayed because it contains the code elements within the filter.

The Maintainability Index column includes a maintainability indicator light that changes based on the maintainability of the code. Green indicates good maintainability, yellow indicates moderate maintainability, and red indicates poor maintainability. The thresholds for the maintainability indicator light and the scale of the Maintainability Index column are still being finalized. Look for more information on this in future blog posts.

Users can also export these results into Excel where they can perform their own calculations and transformations.

Finally, to generate code metrics, simply do the following:

  1. In Solution Explorer, right-click on your solution/project and choose Generate Code Metrics

Download the March CTP (either as a Virtual PC image or a self-extracting install) and tell us what you think! What do you like? What needs improvement? And if we were to add support for additional metrics in the future which ones are you most interested in seeing?

Todd King
Visual Studio Code Analysis Team