Share via


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

Comments

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

  • Anonymous
    February 28, 2007
    Very Cool

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

  • Anonymous
    February 28, 2007
    how do you derive the "manageability index"?

  • Anonymous
    February 28, 2007
    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)
  • Anonymous
    February 28, 2007
    Will the code metrics integrate into Team Build? Will we be able to report against them?

  • Anonymous
    February 28, 2007
    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?

  • Anonymous
    February 28, 2007
    Any chance of this making it into VS 2005?

  • Anonymous
    February 28, 2007
    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).

  • Anonymous
    March 01, 2007
    The FxCop team announced that the new CTP of Orcas now has code metrics . I have the VPC setup for the

  • Anonymous
    March 01, 2007
    How nice... Microsoft reskinned FXCop and NDepends for us.

  • Anonymous
    March 01, 2007
    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...

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

  • Anonymous
    March 01, 2007
    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.

  • Anonymous
    March 01, 2007
    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.

  • Anonymous
    March 01, 2007
    The comment has been removed

  • Anonymous
    March 01, 2007
    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.

  • Anonymous
    March 01, 2007
    Code metrics in VS "Orcas"

  • Anonymous
    March 01, 2007
    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?

  • Anonymous
    March 01, 2007
    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.

  • Anonymous
    March 01, 2007
    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.

  • Anonymous
    March 02, 2007
    The comment has been removed

  • Anonymous
    March 02, 2007
    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?

  • Anonymous
    March 02, 2007
    Buck Hodges on Schema for the WorkspaceMapping.xml file. Michael Ruminer on TFS Event Subscription...

  • Anonymous
    March 02, 2007
    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.

  • Anonymous
    March 02, 2007
    Harry wonders if it has been a slow week. It started that way for me but its certainly not now with both

  • Anonymous
    March 02, 2007
    Please add this for unmanaged C++! The whole world is not managed code folks.

  • Anonymous
    March 03, 2007
    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.

  • Anonymous
    March 03, 2007
    I was just creating some screenshots on Code Metrics in Orcas when I saw the fxcop feed getting bold

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

  • Anonymous
    March 05, 2007
    The comment has been removed

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

  • Anonymous
    March 05, 2007
    C'est énorme (enfin je trouve :-)) : Les fonctionnalités d'analyse de code de Visual Studio Team Edition

  • Anonymous
    March 07, 2007
    Yeah...no code metrics for unmanaged code...there went a day of wasted effort...

  • Anonymous
    March 08, 2007
    Are these metrics based on the individual languages or the generated MSIL?

  • Anonymous
    March 12, 2007
    The comment has been removed

  • Anonymous
    March 15, 2007
    Nice, it's great there's a GUI for this stuff now.  Great work.

  • Anonymous
    April 09, 2007
    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?

  • Anonymous
    April 09, 2007
    Aardvark, Can you post a bug report with a repro project over on http://connect.microsoft.com/VisualStudio? Regards David

  • Anonymous
    April 09, 2007
    It has been posted at https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=269597 .

  • Anonymous
    April 17, 2007
    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.

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

  • Anonymous
    April 24, 2007
    The Visual Studio Code Analysis Team has added code metrics to Visual Studio. You can read their original

  • Anonymous
    April 25, 2007
    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.

  • Anonymous
    April 28, 2007
    Surprise! (not the good kind) If you use FxCop or Visual Studio Static Analysis and haven't yet started

  • Anonymous
    May 03, 2007
    As if you need another reason to download the CTP / Beta 1 of Orcas: Code Metrics

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

  • Anonymous
    June 04, 2007
    Building quality in ! - The next release of Visual Studio Team developer has some very nice features

  • Anonymous
    July 08, 2007
    C'est énorme (enfin je trouve :-)) : Les fonctionnalités d'analyse de code de Visual Studio Team Edition

  • Anonymous
    October 03, 2007
    While we've already briefly spoken about Code Metrics when we announced it , I thought I would discuss

  • Anonymous
    October 04, 2007
    In Visual Studio 2005, we integrated a couple of internal static analysis tools - FxCop and PREfast into

  • Anonymous
    October 05, 2007
    In Visual Studio 2005, we integrated a couple of internal static analysis tools - FxCop and PREfast into

  • Anonymous
    January 29, 2008
    It seems to me pay day cash advance payday loan klingelt�ne f�r handys

  • Anonymous
    February 01, 2008
    At cash advance loan texas pay day cash advance payday loan

  • Anonymous
    February 14, 2008
    Todo list

  • Anonymous
    February 14, 2008
    Todo list

  • Anonymous
    November 11, 2008
    Source Monitor Custom MSBuild Task