Welcome to MSDN Blogs Sign in | Join | Help

Announcing Visual Studio Code Metrics!

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

Published Wednesday, February 28, 2007 8:00 AM by David M. Kean

Comments

Wednesday, February 28, 2007 12:35 PM by O bruxo mobile

# Métricas de codificación

Sin duda, una de las herramientas que más me llamó la atención cuando la conocí era NDepend, una de las

Wednesday, February 28, 2007 1:05 PM by Evan Reiser

# re: Announcing Visual Studio Code Metrics!

Very Cool

Wednesday, February 28, 2007 1:38 PM by Mike Chaliy's Blog

# Метріки коду в новій CTP Orcas

Сьогодні вийшов Visual Studio Orcas - March 2007 CTP. Зкачати його можна тут . Але це мабуть не цікаве,

Wednesday, February 28, 2007 4:32 PM by chris

# re: Announcing Visual Studio Code Metrics!

how do you derive the "manageability index"?

Thursday, March 01, 2007 1:04 AM by Werner

# re: Announcing Visual Studio Code Metrics!

Cool!

last year, i wrote a tool like this, using the

CCI-Assembly from FxCop!

i think it is the same ?

Suggestion/metrics that i want use

-counter: try/finally

-counter: try/catch

-counter: try/catch with reThrow

-counter: tryCatch without Catch-Code

-Counter: Usage of Assert

-Lines of code vs. Lines of Non-Code (using CCI and pdb)

+ many idea from the (german) book: "Code-Quality-Management" (ISBN 3-898643883)

Thursday, March 01, 2007 1:40 AM by Grant Holliday

# re: Announcing Visual Studio Code Metrics!

Will the code metrics integrate into Team Build? Will we be able to report against them?

Thursday, March 01, 2007 1:54 AM by David M. Kean

# re: Announcing Visual Studio Code Metrics!

Chris: Maintainability Index is based on Halstead metrics. In future CTPs, you will see that we've made the number a little more friendly, with a range between 1 and 100.

Werner: Thanks for the feedback. Obviously, it looks like users would like a lot more metrics than the 5 we provide so far.

Grant: Not in the CTP. Is this something you would want to compare build-to-build and track over time?

Thursday, March 01, 2007 2:24 AM by Ranju. V

# re: Announcing Visual Studio Code Metrics!

Any chance of this making it into VS 2005?

Thursday, March 01, 2007 2:28 AM by John Bergman

# re: Announcing Visual Studio Code Metrics!

CodeRush! has had this for quite sometime.  It shows up as a little red number next to the function so you can see it while you are editting.

Its good to see that Visual Studio is going to have Metric that we can track over time (hopefully).

Thursday, March 01, 2007 9:11 AM by Raymond Lewallen [MVP]

# Code metrics available in Orcas March CTP

The FxCop team announced that the new CTP of Orcas now has code metrics . I have the VPC setup for the

Thursday, March 01, 2007 9:38 AM by GoodSyntax

# re: Announcing Visual Studio Code Metrics!

How nice...

Microsoft reskinned FXCop and NDepends for us.

Thursday, March 01, 2007 9:50 AM by hessie

# re: Announcing Visual Studio Code Metrics!

That's a really great feature!

But I guess it is only available with managed code?

I'd really love to do this with C++ also, as I got a huge codebase there...

Thursday, March 01, 2007 10:10 AM by Kevin I

# re: Announcing Visual Studio Code Metrics!

Any chance that Rico Mariani's metrics for the framework could be integrated in some way as well, to show potentially 'fat' functions?

Kevin

Thursday, March 01, 2007 10:29 AM by David M. Kean

# re: Announcing Visual Studio Code Metrics!

Ranju: This won't make it into Visual Studio 2005, only 'Orcas'.

John: Unfortunately, there is no overlay on the editor. What would you like to see around this? Perhaps something similar to the code coverage overlay?

hessie: This is only for managed code, including C#, Visual Basic and C++/CLI.

Kevin: That's a really awesome idea. Expect to some of Rico's work in some other form in the future.

Thursday, March 01, 2007 10:44 AM by Patrick Smacchia

# re: Announcing Visual Studio Code Metrics!

The tool NDepend has support for many metrics.

http://www.ndepend.com/Metrics.aspx

Also results can be visualized in a treemap, and sifted with a dedicated language that looks like SQL:

SELECT METHODS FROM NAMESPACE "MyNamespace" WHERE CyclomaticComplexity > 20 OR NbLinesOfCode > 50

A dependency structure matrix allows to browse coupling between assemblies/namespaces/classes/members

Soon, NDepend will allow to see differences between 2 builds.

Thursday, March 01, 2007 11:25 AM by Jasmine

# re: Announcing Visual Studio Code Metrics!

"This won't make it into Visual Studio 2005, only 'Orcas'."

...then who cares? Give me something I can use. Tooting your own horn about stuff that isn't available yet is starting to really drive me nuts (with the whole industry). Don't announce products that aren't ready yet!

Thursday, March 01, 2007 11:48 AM by David M. Kean

# re: Announcing Visual Studio Code Metrics!

Jasmine: I understand how you feel, I was a customer of Microsoft just over a year ago. However, we announce and provide you an early look at these features so that you can have an impact on them. Once the feature has been released, it's too late to fix bugs and broken designs. The early we release these, the more time we have to react to customer feedback.

However, stayed tuned, we will still continue to provide tips and information that you can use today in both Visual Studio 2005 and FxCop 1.35.

Thursday, March 01, 2007 6:31 PM by Daniel Moth

# Code metrics in VS "Orcas"

Code metrics in VS "Orcas"

Thursday, March 01, 2007 10:39 PM by Scott

# re: Announcing Visual Studio Code Metrics!

Integrating with Team Build would be great! I think being able to do build-to-build comparisons and trending would be very helpful.

Will there be an "extension" interface that allows us to develop our own metrics that can plug in to this framework?

Friday, March 02, 2007 12:22 AM by Anthony Towry

# re: Announcing Visual Studio Code Metrics!

This is a very cool feature that's long overdue.  I'm not sure how much I like the overlay idea though at least not on by default.

Friday, March 02, 2007 4:07 AM by Cleve Littlefield

# re: Announcing Visual Studio Code Metrics!

Integration into Team build is a must, so we can report and trend this over time.  Integration with VSTS work items would be cool so we can do things like relate # of bugs to cyclomatic complexity or LOC.

Lines of code/lines of comments is important.

For ASP.Net, lines of JS and lines of HTML.

Would be nice if it worked for VSTS for DB to get # of SQL loc.

Friday, March 02, 2007 8:32 AM by Wayne M.

# re: Announcing Visual Studio Code Metrics!

So how do they get a CCM of 0?  A 1 indicates a straight line function with no branches and loops.  Why does the CCM have two decimal places?  CCM gives an integral result.  

Friday, March 02, 2007 8:42 AM by Daniel

# re: Announcing Visual Studio Code Metrics!

Will this be available in Orcas "Professional" (ie not just the $10K+ Team products.)?  I was disappointed that FxCop was only available integrated in Team System.  I think things like this should be seen as an important learning aid, much like intellisense.  Come to think of it, will MS be keeping the same Express/Standard/Pro/Team lineup for Orcas?

Friday, March 02, 2007 10:13 AM by Team System News

# VSTS Links - 03/02/2007

Buck Hodges on Schema for the WorkspaceMapping.xml file. Michael Ruminer on TFS Event Subscription...

Friday, March 02, 2007 10:52 AM by David M. Kean

# re: Announcing Visual Studio Code Metrics!

Wayne: Cyclomatic Complexity of 0 means that there is no code within a type. We have fixed the decimal places and the rollups in later builds.

Friday, March 02, 2007 2:57 PM by Sam Gentile

# New and Notable 147

Harry wonders if it has been a slow week. It started that way for me but its certainly not now with both

Friday, March 02, 2007 7:16 PM by John Schroedl

# re: Announcing Visual Studio Code Metrics!

Please add this for unmanaged C++! The whole world is not managed code folks.

Saturday, March 03, 2007 9:32 AM by Chris Woolderink

# How is Maintainability Index calculated?

How do you calculate the Maintainability Index exactly? Only based on Halstead metrics as mentioned before? Or is this based on the formula of Oman (which also includes Cyclomatic Complexity, LOC, Comments)? Or another formula?

I am very curious about this, as I am preparing a Master Thesis research to determine an indicator for maintainability by using .NET code analysis.

Saturday, March 03, 2007 8:14 PM by B# .NET Blog

# New in Orcas - Code Metrics

I was just creating some screenshots on Code Metrics in Orcas when I saw the fxcop feed getting bold

Sunday, March 04, 2007 10:11 AM by Jeff Beehler's Blog

# One more goodie with the March CTP

There really is just so much in the recently released Visual Studio March CTP that it's frankly hard

Monday, March 05, 2007 1:17 PM by Keith Patrick

# re: Announcing Visual Studio Code Metrics!

"Lines of code/lines of comments is important"

On that note, a statement count would be good to have (I use a lot of lines for single statements, so my line count is skewed)

I'd also like to see some kind of metric corresponding to the amount of exceptions that are explicitly thrown in code (even references) but not caught anywhere..it's been one I've wanted for a while (ties into XML documentation of exceptions, as well)

Maybe some security metrics as well, such as some kind of safety profile based on number of unmanaged calls, requested permissions that go unused, etc.

Monday, March 05, 2007 3:44 PM by 米田 Blog ( SQL Server MEMO )

# Visual Studio "Orcas" にCode Metrics機能がつく(今回 March 2007 CTPより提供)

Visual Studio "Orcas" にCode Metrics機能がつく(今回 March 2007 CTPより提供)

Tuesday, March 06, 2007 6:41 AM by Visual Studio Team System en direct de Microsoft France

# Visual Studio Code Metrics : disponible dès Visual Studio Orcas !

C'est énorme (enfin je trouve :-)) : Les fonctionnalités d'analyse de code de Visual Studio Team Edition

Wednesday, March 07, 2007 10:30 AM by Rob Bryce

# re: Announcing Visual Studio Code Metrics!

Yeah...no code metrics for unmanaged code...there went a day of wasted effort...

Thursday, March 08, 2007 10:36 PM by Scott Rudy

# re: Announcing Visual Studio Code Metrics!

Are these metrics based on the individual languages or the generated MSIL?

Monday, March 12, 2007 3:31 PM by Steve

# Three must-have checks

Add two checks:

- Dangling property

- Fat body

- Else slope

Dangling property: Check specifically for properties that have Get and set methods that only do the default behavior.  We've thousands of non-useful spacefiller lines of code filled with dangling properties based on old coding standards.

Fat Body: Flag loops with a fat body such as a for loop with a body longer than 50 lines.

Else Slope: Flag methods/blocks of code that have large amounts of code in the IF block and 1 or two lines of code in the else block.  Especially, flag the methods with multiple levels of unnessary nesting like:

void TooNest(int a)

{

if (a > 0)

 {

 if (a | 1)

    {

    if ((a | 3) == 3)

        {

        (more than 20 lines of code)

        }

     else

        return(a + 1);

    }

 else

    retun(5);

 }

else

 return(a -1);

return(a);

}

The main criteria is excessive nesting combined with a large ration of (number of lines in if part) / (number of lines in else part)

Thursday, March 15, 2007 11:43 AM by Peter Ritchie

# re: Announcing Visual Studio Code Metrics!

Nice, it's great there's a GUI for this stuff now.  Great work.

Monday, April 09, 2007 1:48 PM by Aardvark

# re: Announcing Visual Studio Code Metrics!

I have been trying to use "Generate Code Metrics" with my C# project using the March CTP and it tells me "This file contains no managed code.".  That is a bit odd because it is all managed code except for some DllImport's in my NativeMethods class.  If I use the "Run Code Analysis" option, I do get some Cyclomatic Complexity reports back so some of the analysis is working.  Any ideas?

Monday, April 09, 2007 1:52 PM by David M. Kean

# re: Announcing Visual Studio Code Metrics!

Aardvark,

Can you post a bug report with a repro project over on http://connect.microsoft.com/VisualStudio?

Regards

David

Monday, April 09, 2007 2:57 PM by Aardvark62

# re: Announcing Visual Studio Code Metrics!

Tuesday, April 17, 2007 12:45 PM by Jon

# re: Announcing Visual Studio Code Metrics!

I can relate to so many of the posts. I like the metrics but it should be incorporated into Code Analysis such that the build will fail if you are not within acceptable ranges. The problem with making it an optional tool is some developers in my group will use it, but others will not. This is a way to enforce good programming practices.

My general opionion of the Microsoft suite of tools is that you do not provide enough functionality. It always seems like 80% of the functionality is there but your always waiting for the other 20% (ie sharepoint, ajax, continuous integration, code analysis etc)

I've become frustrated with the "in the next version" mentality and will not spend my time integrating partial products or searching for the small amount of documentation that exists to write some custom processes. If you don't include all of the necessary functionality I'll look elsewhere.

Thursday, April 19, 2007 3:16 AM by Tom Lee's blog

# Visual Studio Code Metrics

Software Metrics 是將軟體設計或規格加以量測與量化的科學,過去在 Visual Studio 2005 Team Edition for Developers 版本中僅提供了靜態程式碼分析

Wednesday, April 25, 2007 12:24 AM by The Story So Far

# Visual Studio Code Metrics

The Visual Studio Code Analysis Team has added code metrics to Visual Studio. You can read their original

Wednesday, April 25, 2007 8:52 PM by Andy Bliven

# Rolling up Cyclometric Complexity

A more useful measure of the complexity of a class is the average complexity of each method in it.  Since this value is normalized it can be used to compare two classes to decide which is more likely to be a maintainence risk, while the simple sum cannot.  Alternatively you could define the complexity of the class to be the maximum of the complexity of all its methods, which is similarly useful.

I suppose you've thought of making the metric computation an extension point so I can add my own, perhaps calculated from the primitive measures you've already computed (# methods, # operators, etc.)?  You'll never get away with just this fixed set!  

I am delighted to see this in Visual Studio, it's a great feature.

Saturday, April 28, 2007 8:49 AM by I may have joined the wrong side

# Control flow engine, 200?-2007, RIP

Surprise! (not the good kind) If you use FxCop or Visual Studio Static Analysis and haven't yet started

Thursday, May 03, 2007 9:53 AM by Knowledge, Insight, Action; In that order!

# Code Metrics in Orcas

As if you need another reason to download the CTP / Beta 1 of Orcas: Code Metrics

Sunday, May 06, 2007 12:07 PM by The Visual Studio Code Analysis Team Blog

# Visual Studio 'Orcas' Beta 1 Released!

If you've been living under a rock (or just distracted by this Silverlight thingy), you might have missed

Tuesday, June 05, 2007 12:07 AM by The Liquidator

# Code Analysis and Code Metrics - Orcas Team Developer & Suite

Building quality in ! - The next release of Visual Studio Team developer has some very nice features

Monday, July 09, 2007 3:15 AM by Visual Studio Team System

# Visual Studio Code Metrics : disponible dès Visual Studio Orcas !

C'est énorme (enfin je trouve :-)) : Les fonctionnalités d'analyse de code de Visual Studio Team Edition

Wednesday, October 03, 2007 11:50 AM by The Visual Studio Code Analysis Team Blog

# New for Visual Studio 2008 - Code Metrics

While we've already briefly spoken about Code Metrics when we announced it , I thought I would discuss

Thursday, October 04, 2007 8:43 PM by Noticias externas

# Code Analysis Features in VS 2008

In Visual Studio 2005, we integrated a couple of internal static analysis tools - FxCop and PREfast into

Friday, October 05, 2007 1:33 PM by Somasegar's WebLog

# Code Analysis Features in VS 2008

In Visual Studio 2005, we integrated a couple of internal static analysis tools - FxCop and PREfast into

Tuesday, January 29, 2008 10:34 AM by juegos de poker en espa�ol

# advance card cash credit

It seems to me pay day cash advance payday loan klingelt�ne f�r handys

Saturday, February 02, 2008 2:39 AM by advance america cash first

# cash advance detroit

At cash advance loan texas pay day cash advance payday loan

Thursday, February 14, 2008 5:36 PM by Laumania.net

# Todo list

Todo list

Thursday, February 14, 2008 5:36 PM by Laumania.net

# Todo list

Todo list

Tuesday, November 11, 2008 5:57 PM by markscottjohnson.com

# Source Monitor Custom MSBuild Task

Source Monitor Custom MSBuild Task

New Comments to this post are disabled
 
Page view tracker