[# TEAMBUILD2010] HowTo: Add Code Metrics in the execution of a Build

image47dd1de4

Good,

based on the post I wrote a few days ago about how to create a Build definition to perform code analysis using StyleCopfor Team Build 2010 using the tfs build extensions, today plays a similar post but to incorporate an analysis of metrics of code in the execution of a build.

Para esto nos basaremos en el post anterior, pero a partir del punto 9 crearemos una nueva definición de Team Build, y seguiremos los siguientes pasos:

1. Una vez agregadas las referencias para poder utilizar Tfs Build Extensions, podremos ver que en la toolbox poseemos una actividad llamada [Code Metrics]. Esta actividad es la que utilizaremos para realizar el análisis de código.

image

2. Dentro de la opcion

Secuence > Run on Agent > Try Compile, Test, and Associate Changesets and Work Items > Secuence > Compile, Test, and Associate Changesets and Work Items > Try Compile and Test > Compile and Test > For Each Configuration in BuildSettings.PlatformConfigurations > Compile and Test for Configuration > If BuildSettings.HasProjectsToBuild > For Each Project in BuildSettings.ProjectsToBuild > Try to Compile the Project > Compile the Project

luego de la actividad [Run MSBuild for Project], agregaremos una Secuence a la que llamaremos [Run Code Metrics Analysis]

image

3. In the sequence we will add 2 activities of type [WriteBuildMessage] to display the start and end of the process of Code Metrics analysis.

  • Start Activity
  • DisplayName = Start Code Metrics Analysis
  • Message = “start code metrics analysis”
  • Finish Activity
  • DisplayName = Finish Code Metrics Analysis
  • Message = “finish code metrics analysis”

4. Between the two activities add a new activity type [Code Metrics] with the following properties defined

  • DisplayName = Run Code Metrics Analysis
  • BinariesDirectory = BinariesDirectory
  • CyclomaticComplexityErrorThreshold = 40
  • CyclomaticComplexityWarningThreshold = 15
  • MaintanabilityIndexErrorThreshold = 10
  • MaintanabilityIndexWarningThreshold = 90
  • FilesToProcess = New List(Of_String) (New String() {“ElBruno.StyleCopBuild.Demo.dll”})

Clarification: If you put the filter in “*.dll”, Code Metrics process try to analizr also the dll of unit testing and for loading the same need for several assembled the IDE from Visual Studio 2010.

5 We protect our changes in the Source Control Server and we can now create a new Build definition for this process.

6 On the basis of the definition of build you create 2 days ago, I make a cloned it, displaying the context menu and selecting the [Clone build definition]]

image

7. In the new definition of build that has been created, change the name of the same, for this example would be [team Build.Code metrics] and then I must change the template for capturing of the build.

8. To change the template, select the section [Process] and despliego the details of the template.

image

9 Combo templates by default not should show my new template, so select the option [New] and then the option [Select an existing XAML file]].

10 A [Browse] about Source Control, seleciono the template I created in the first steps [BuildTemplateWithCodeMetrics.xaml] and her assigned as a template for implementation.

image

11 Keep the definition of the build and at the time of launch the same, I find that there are a couple of data in the result of the build to take into account:

image

And you have not met “the limits” for Code Metrics analysis, because the build is not as a success, but it appears to us as Partially succeded. Among the list of errors and warnings cannot see the reason for this State.

12. Finally comment on the execution log we can see the detail for each element of our assembled from the Code Metrics analysis.

image

The example code can be downloaded from:

https://SkyDrive.live.com/embedicon.aspx/code%20Samples/2011%2007%2013%20CodeMetricsDemo.zip?CID=bef06dffdb192125 & sc = documents

 

Greetings @ somewhere between Madrid and Caudete

The Bruno

   

One thought on “[# TEAMBUILD2010] HowTo: Add Code Metrics in the execution of a Build

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.