7. October 2009 04:32
In Visual Studio 2008, Microsoft has added the code metrics, which gives you information about the quality and maintainability of the application. Unfortunately you can not easily start the code metrics automically, and you can not integrate it from Team Build.
There is NDepend, which has the ability to integrate with team build, that gives you access to the same code metrics. But NDepend does not have a repository so you can build a trend of the metrics for all your applications stored in your TFS source control.
So I created a solution which works around these problems.
The idea of the application is quite simple:
- Download all sources in TFS to the local drive
- One by one open the solution
- For each solution calculate the code metrics
- Store the results of the code metrics in a database for reporting and trend analysis
It is do-able, but it was a long story to get a solution that works. I like to share the solution with you.
- EntLib 4.0
- SQL Server 2005
- Visual Studio 2008 Development Edition or Team Suite
- Team Foundation Server 2008
- Microsoft Excel 2003 (not tested on Excel 2007)
To start the application, do the following:
Download the sources at the bottom of the page.
Open the solution
Deploy the CodeMetricsDatabase project to the SQL Server of your choice
Set the connection string to the SQL Server the database project is deployed to
Open the app.config
Change the CodeMetrics connection string in the connectionStrings section
Start the application with the following parameters:
TFS server name (for example http://tfsserver:8080)
Start node in TFS source control (for example $/MyTeamProject/MySolution)
The local path where the sources are stored (for example c:\CodeMetricsCache)
And optional you can pass the Team Project you are only interested in
GatherCodeMetrics.zip (289.11 kb)
To be able to see the trend of the metrics, I have created a report which you can install on the TFS Reporting site. To install the report, you must add a datasource called "CodeMetrics". This datasource must have the connection information to the database where you store the code metrics.
The second step is to update the rdl below. You can now see the trend of the code metrics of all your applications.
Code Metrics Trend.rdl (34.71 kb)