Exploring the Code Metrics Tool in Visual Studio

Exploring the Code Metrics Tool in Visual Studio

This is the 7th post in this series on understanding code complexity and maintainability.  Over the last few posts we have covered all the different types of a code metrics (Line Of Code , Class Coupling , Depth of Inheritance , Cyclomatic Complexity  and Maintainability Index) and internal of each of the items. In this post, lets have a look at the different tooling aspect of Code Metrics Tools that can help us better in using the code metrics data.

Here is the quick list of additional features that Code Metrics Tools in Visual Studio provides

  • Filter the Metrics Data
  • Export to Excel
  • Create TFS Work Item Directly
  • Add / Remove Metrics Columns

Let’s start looking into them one by one.

Filter the Metrics Data

Filtering the Code Metrics data could be a very frequent requirements for the developers. The Code Metric Tool has an extended support for the filtering the data

  • based on the type of code metrics
  • and additionally by providing min and max value of indexes of the selected metrics

image

As shown in the below screenshot, the filter has been applied on “Class Coupling” with the min value of 5 and max value of 7.

image

By using this feature, you can easily find out your respective code block / area where you need to work more.

Code Metric Filter list also maintain the Most Recently used filters details.

image

Export to Excel

Another very useful feature of Code Metrics tool is “Export to Excel”; which can be used to export the metrics results into an excel file.

image

Here is a sample exported excel data from the code metrics results.

image

Quick Fact:

If you have the code metrics filter enabled in the tool, and then  use export to excel, you will have the same filter applied in the exported sheet.

For an example, if you have the code metrics filters set as following (Class Coupling  5- 7 ) and  then export the information into excel file.

image

The exported excel will have the filter enabled for the class coupling with the value defined. The excel contain all the information form the code metrics tool, you need to remove the filter to get those data back in display.

image

Once you have the information exported to excel, you can use your data in the way you want.

Create TFS Work Item Directly

If you want to keep track of Code metrics items which needs to fix and want to assign them to respective team members, you can do it very easily. Well, the “Create Work Item” option directly create the work item in TFS.

image

The TFS Work item will have the details of code metrics information including code metrics values.image

Add / Remove Metrics Columns

You can Add / Remove Metrics columns by selecting the options from “Add / Remove Columns” options

image

By default all the five types of metrics are checked.

image

Incase if you want to focus any specific types of Metrics values, you can choose and select those columns and deselect the rest.

image

 

well, here is another small and useful utility of the tool. You can run / rerun the metrics from the tool itself by clicking on the “Calculate Code Metrics for Solution” button itself.

image

That’s it.  The Code Metrics features is very powerful to ensure your code is written properly and well maintained.  Take the advantages of all additional features of code metrics tool.

Must Read :

 

Hope this helps !

Abhijit Jana

Abhijit runs the Daily .NET Tips. He started this site with a vision to have a single knowledge base of .NET tips and tricks and share post that can quickly help any developers . He is a Former Microsoft ASP.NET MVP, CodeProject MVP, Mentor, Speaker, Author, Technology Evangelist and presently working as a .NET Consultant. He blogs at http://abhijitjana.net , you can follow him @AbhijitJana . He is the author of book Kinect for Windows SDK Programming Guide.

2 Comments to “Exploring the Code Metrics Tool in Visual Studio”

Comments are closed.