[TEAMBUILD2010] HowTo: Add results of analysis of code metrics in a Build (I)

image47dd1de4

Good,

Since a couple of versions in the Visual Studio IDE, we have the ability to perform analysis of code metrics in our solutions.In this analysis we can see the complexity cyclomatic code, the coupling between classes, and other metrics that will help us to see if the quality of our code is acceptable. The problem with the results of this tool is that it is not possible to incorporate those metrics “out of the box” in the result of a build. In this post I will show how you can add the result to a build and work on it.

For this delivery of a code to run when metrics of code returns the following values:

image

And prior to the cloth, i.e. a couple of custom tasks, play ugly xmls, see the prerequisites. In this case is very simple:

Download the Visual Studio Code Metrics Power Tools 10.0 for Visual Studio 2010 fromhttp://www.microsoft.com/downloads/en/details.aspx?FamilyID = edd1dfb0-b9fe-4e90-b6a6-5ed6f6f6e615

The Visual Studio Code Metrics Power Tools 10.0 consist of a tool command line allows us to analyze assembled.NET. Once downloaded and installed the PT, the same work in a very simple way:

On a compiled assembly of.NET, launches the application [% Program Files%\Microsoft Visual Studio 10. 0\Team Tools\Static Analysis Tools\FxCop\metrics.exe] and it generates a xml with the results of the analysis of code metrics.

For example, on the previous application that is compiled in the location

E:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCodeMetrics\bin\Debug\

It should launch the following command from the command line:

   1:
   2: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop>;
   3: Metrics.exe
   4:   /f:e:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCodeMetrics\bin\Debug\teambuildcodemetrics.exe
   5:   /out:e:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCodeMetrics\bin\Debug\codemetrics.xml
   6:
   7: Microsoft (R) Code Metrics Command-Line Tool, Version 10.0
   8: Copyright (C) Microsoft Corporation.  All rights reserved.
   9:
  10: Calculating metrics for file
  11: 'e:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCodeMetrics\bin\Debug\TeamBuildCodeMetrics.exe'.
  12: Writing report to e:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCo
  13: deMetrics\bin\Debug\codemetrics.xml...
  14: Done.
  15:
  16: C:\Program Files (x86)\Microsoft Visual Studio 10.0\Team Tools\Static Analysis Tools\FxCop>

This action creates the following xml with the information of the previous project code metrics analysis.

   1: <?xml version="1.0" encoding="utf-8"?>
   2: <CodeMetricsReport Version="10.0">
   3:   <Targets>
   4:     <Target Name="e:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCodeMetrics\bin\Debug\TeamBuildCodeMetrics.exe">
   5:       <Modules>
   6:         <Module Name="TeamBuildCodeMetrics.exe" AssemblyVersion="1.0.0.0" FileVersion="1.0.0.0">
   7:           <Metrics>
   8:             <Metric Name="MaintainabilityIndex" Value="95" />
   9:             <Metric Name="CyclomaticComplexity" Value="24" />
  10:             <Metric Name="ClassCoupling" Value="14" />
  11:             <Metric Name="DepthOfInheritance" Value="12" />
  12:             <Metric Name="LinesOfCode" Value="47" />
  13:           </Metrics>
  14:           <Namespaces>
  15:             <Namespace Name="TeamBuildCodeMetrics">
  16:               <Metrics>
  17:                 <Metric Name="MaintainabilityIndex" Value="95" />
  18:                 <Metric Name="CyclomaticComplexity" Value="24" />
  19:                 <Metric Name="ClassCoupling" Value="14" />
  20:                 <Metric Name="DepthOfInheritance" Value="12" />
  21:                 <Metric Name="LinesOfCode" Value="47" />
  22:               </Metrics>
  23:               <Types>
  24:                 <Type Name="Program">
  25:                   <Metrics>
  26:                     <Metric Name="MaintainabilityIndex" Value="55" />
  27:                     <Metric Name="CyclomaticComplexity" Value="11" />
  28:                     <Metric Name="ClassCoupling" Value="13" />
  29:                     <Metric Name="DepthOfInheritance" Value="1" />
  30:                     <Metric Name="LinesOfCode" Value="32" />
  31:                   </Metrics>
  32:                   <Members>
  33:                     <Member Name="Main(string[]) : void" File="E:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCodeMetrics\Program.cs" Line="8">
  34:                       <Metrics>
  35:                         <Metric Name="MaintainabilityIndex" Value="46" />
  36:                         <Metric Name="CyclomaticComplexity" Value="10" />
  37:                         <Metric Name="ClassCoupling" Value="13" />
  38:                         <Metric Name="LinesOfCode" Value="31" />
  39:                       </Metrics>
  40:                     </Member>
  41:                     <Member Name="Program()">
  42:                       <Metrics>
  43:                         <Metric Name="MaintainabilityIndex" Value="100" />
  44:                         <Metric Name="CyclomaticComplexity" Value="1" />
  45:                         <Metric Name="ClassCoupling" Value="0" />
  46:                         <Metric Name="LinesOfCode" Value="1" />
  47:                       </Metrics>
  48:                     </Member>
  49:                   </Members>
  50:                 </Type>
  51:                 <Type Name="Class1">
  52:                   <Metrics>
  53:                     <Metric Name="MaintainabilityIndex" Value="85" />
  54:                     <Metric Name="CyclomaticComplexity" Value="2" />
  55:                     <Metric Name="ClassCoupling" Value="1" />
  56:                     <Metric Name="DepthOfInheritance" Value="1" />
  57:                     <Metric Name="LinesOfCode" Value="4" />
  58:                   </Metrics>
  59:                   <Members>
  60:                     <Member Name="GetData() : int" File="E:\srcBcapuano\AgileLabs\Blog\TeamBuildCodeMetrics\TeamBuildCodeMetrics\Class1.cs" Line="8">
  61:                       <Metrics>
  62:                         <Metric Name="MaintainabilityIndex" Value="80" />
  63:                         <Metric Name="CyclomaticComplexity" Value="1" />
  64:                         <Metric Name="ClassCoupling" Value="1" />
  65:                         <Metric Name="LinesOfCode" Value="3" />
  66:                       </Metrics>
  67:                     </Member>
  68:                     <Member Name="Class1()">
  69:                       <Metrics>
  70:                         <Metric Name="MaintainabilityIndex" Value="100" />
  71:                         <Metric Name="CyclomaticComplexity" Value="1" />
  72:                         <Metric Name="ClassCoupling" Value="0" />
  73:                         <Metric Name="LinesOfCode" Value="1" />
  74:                       </Metrics>
  75:                     </Member>
  76:                   </Members>
  77:                 </Type>
  78:                 <Type Name="Class2">
  79:                   <Metrics>
  80:                     <Metric Name="MaintainabilityIndex" Value="100" />
  81:                     <Metric Name="CyclomaticComplexity" Value="1" />
  82:                     <Metric Name="ClassCoupling" Value="1" />
  83:                     <Metric Name="DepthOfInheritance" Value="2" />
  84:                     <Metric Name="LinesOfCode" Value="1" />
  85:                   </Metrics>
  86:                   <Members>
  87:                     <Member Name="Class2()">
  88:                       <Metrics>
  89:                         <Metric Name="MaintainabilityIndex" Value="100" />
  90:                         <Metric Name="CyclomaticComplexity" Value="1" />
  91:                         <Metric Name="ClassCoupling" Value="1" />
  92:                         <Metric Name="LinesOfCode" Value="1" />
  93:                       </Metrics>
  94:                     </Member>
  95:                   </Members>
  96:                 </Type>
  97:                 <Type Name="Class3">
  98:                   <Metrics>
  99:                     <Metric Name="MaintainabilityIndex" Value="100" />
 100:                     <Metric Name="CyclomaticComplexity" Value="1" />
 101:                     <Metric Name="ClassCoupling" Value="1" />
 102:                     <Metric Name="DepthOfInheritance" Value="3" />
 103:                     <Metric Name="LinesOfCode" Value="1" />
 104:                   </Metrics>
 105:                   <Members>
 106:                     <Member Name="Class3()">
 107:                       <Metrics>
 108:                         <Metric Name="MaintainabilityIndex" Value="100" />
 109:                         <Metric Name="CyclomaticComplexity" Value="1" />
 110:                         <Metric Name="ClassCoupling" Value="1" />
 111:                         <Metric Name="LinesOfCode" Value="1" />
 112:                       </Metrics>
 113:                     </Member>
 114:                   </Members>
 115:                 </Type>
 116:                 <Type Name="Class4">
 117:                   <Metrics>
 118:                     <Metric Name="MaintainabilityIndex" Value="100" />
 119:                     <Metric Name="CyclomaticComplexity" Value="1" />
 120:                     <Metric Name="ClassCoupling" Value="1" />
 121:                     <Metric Name="DepthOfInheritance" Value="4" />
 122:                     <Metric Name="LinesOfCode" Value="1" />
 123:                   </Metrics>
 124:                   <Members>
 125:                     <Member Name="Class4()">
 126:                       <Metrics>
 127:                         <Metric Name="MaintainabilityIndex" Value="100" />
 128:                         <Metric Name="CyclomaticComplexity" Value="1" />
 129:                         <Metric Name="ClassCoupling" Value="1" />
 130:                         <Metric Name="LinesOfCode" Value="1" />
 131:                       </Metrics>
 132:                     </Member>
 133:                   </Members>
 134:                 </Type>
 135:                 <Type Name="Class5">
 136:                   <Metrics>
 137:                     <Metric Name="MaintainabilityIndex" Value="100" />
 138:                     <Metric Name="CyclomaticComplexity" Value="1" />
 139:                     <Metric Name="ClassCoupling" Value="1" />
 140:                     <Metric Name="DepthOfInheritance" Value="5" />
 141:                     <Metric Name="LinesOfCode" Value="1" />
 142:                   </Metrics>
 143:                   <Members>
 144:                     <Member Name="Class5()">
 145:                       <Metrics>
 146:                         <Metric Name="MaintainabilityIndex" Value="100" />
 147:                         <Metric Name="CyclomaticComplexity" Value="1" />
 148:                         <Metric Name="ClassCoupling" Value="1" />
 149:                         <Metric Name="LinesOfCode" Value="1" />
 150:                       </Metrics>
 151:                     </Member>
 152:                   </Members>
 153:                 </Type>
 154:                 <Type Name="Class6">
 155:                   <Metrics>
 156:                     <Metric Name="MaintainabilityIndex" Value="100" />
 157:                     <Metric Name="CyclomaticComplexity" Value="1" />
 158:                     <Metric Name="ClassCoupling" Value="1" />
 159:                     <Metric Name="DepthOfInheritance" Value="6" />
 160:                     <Metric Name="LinesOfCode" Value="1" />
 161:                   </Metrics>
 162:                   <Members>
 163:                     <Member Name="Class6()">
 164:                       <Metrics>
 165:                         <Metric Name="MaintainabilityIndex" Value="100" />
 166:                         <Metric Name="CyclomaticComplexity" Value="1" />
 167:                         <Metric Name="ClassCoupling" Value="1" />
 168:                         <Metric Name="LinesOfCode" Value="1" />
 169:                       </Metrics>
 170:                     </Member>
 171:                   </Members>
 172:                 </Type>
 173:                 <Type Name="Class7">
 174:                   <Metrics>
 175:                     <Metric Name="MaintainabilityIndex" Value="100" />
 176:                     <Metric Name="CyclomaticComplexity" Value="1" />
 177:                     <Metric Name="ClassCoupling" Value="1" />
 178:                     <Metric Name="DepthOfInheritance" Value="7" />
 179:                     <Metric Name="LinesOfCode" Value="1" />
 180:                   </Metrics>
 181:                   <Members>
 182:                     <Member Name="Class7()">
 183:                       <Metrics>
 184:                         <Metric Name="MaintainabilityIndex" Value="100" />
 185:                         <Metric Name="CyclomaticComplexity" Value="1" />
 186:                         <Metric Name="ClassCoupling" Value="1" />
 187:                         <Metric Name="LinesOfCode" Value="1" />
 188:                       </Metrics>
 189:                     </Member>
 190:                   </Members>
 191:                 </Type>
 192:                 <Type Name="Class8">
 193:                   <Metrics>
 194:                     <Metric Name="MaintainabilityIndex" Value="100" />
 195:                     <Metric Name="CyclomaticComplexity" Value="1" />
 196:                     <Metric Name="ClassCoupling" Value="1" />
 197:                     <Metric Name="DepthOfInheritance" Value="8" />
 198:                     <Metric Name="LinesOfCode" Value="1" />
 199:                   </Metrics>
 200:                   <Members>
 201:                     <Member Name="Class8()">
 202:                       <Metrics>
 203:                         <Metric Name="MaintainabilityIndex" Value="100" />
 204:                         <Metric Name="CyclomaticComplexity" Value="1" />
 205:                         <Metric Name="ClassCoupling" Value="1" />
 206:                         <Metric Name="LinesOfCode" Value="1" />
 207:                       </Metrics>
 208:                     </Member>
 209:                   </Members>
 210:                 </Type>
 211:                 <Type Name="Class9">
 212:                   <Metrics>
 213:                     <Metric Name="MaintainabilityIndex" Value="100" />
 214:                     <Metric Name="CyclomaticComplexity" Value="1" />
 215:                     <Metric Name="ClassCoupling" Value="1" />
 216:                     <Metric Name="DepthOfInheritance" Value="9" />
 217:                     <Metric Name="LinesOfCode" Value="1" />
 218:                   </Metrics>
 219:                   <Members>
 220:                     <Member Name="Class9()">
 221:                       <Metrics>
 222:                         <Metric Name="MaintainabilityIndex" Value="100" />
 223:                         <Metric Name="CyclomaticComplexity" Value="1" />
 224:                         <Metric Name="ClassCoupling" Value="1" />
 225:                         <Metric Name="LinesOfCode" Value="1" />
 226:                       </Metrics>
 227:                     </Member>
 228:                   </Members>
 229:                 </Type>
 230:                 <Type Name="Class10">
 231:                   <Metrics>
 232:                     <Metric Name="MaintainabilityIndex" Value="100" />
 233:                     <Metric Name="CyclomaticComplexity" Value="1" />
 234:                     <Metric Name="ClassCoupling" Value="1" />
 235:                     <Metric Name="DepthOfInheritance" Value="10" />
 236:                     <Metric Name="LinesOfCode" Value="1" />
 237:                   </Metrics>
 238:                   <Members>
 239:                     <Member Name="Class10()">
 240:                       <Metrics>
 241:                         <Metric Name="MaintainabilityIndex" Value="100" />
 242:                         <Metric Name="CyclomaticComplexity" Value="1" />
 243:                         <Metric Name="ClassCoupling" Value="1" />
 244:                         <Metric Name="LinesOfCode" Value="1" />
 245:                       </Metrics>
 246:                     </Member>
 247:                   </Members>
 248:                 </Type>
 249:                 <Type Name="Class11">
 250:                   <Metrics>
 251:                     <Metric Name="MaintainabilityIndex" Value="100" />
 252:                     <Metric Name="CyclomaticComplexity" Value="1" />
 253:                     <Metric Name="ClassCoupling" Value="1" />
 254:                     <Metric Name="DepthOfInheritance" Value="11" />
 255:                     <Metric Name="LinesOfCode" Value="1" />
 256:                   </Metrics>
 257:                   <Members>
 258:                     <Member Name="Class11()">
 259:                       <Metrics>
 260:                         <Metric Name="MaintainabilityIndex" Value="100" />
 261:                         <Metric Name="CyclomaticComplexity" Value="1" />
 262:                         <Metric Name="ClassCoupling" Value="1" />
 263:                         <Metric Name="LinesOfCode" Value="1" />
 264:                       </Metrics>
 265:                     </Member>
 266:                   </Members>
 267:                 </Type>
 268:                 <Type Name="Class12">
 269:                   <Metrics>
 270:                     <Metric Name="MaintainabilityIndex" Value="100" />
 271:                     <Metric Name="CyclomaticComplexity" Value="1" />
 272:                     <Metric Name="ClassCoupling" Value="1" />
 273:                     <Metric Name="DepthOfInheritance" Value="12" />
 274:                     <Metric Name="LinesOfCode" Value="1" />
 275:                   </Metrics>
 276:                   <Members>
 277:                     <Member Name="Class12()">
 278:                       <Metrics>
 279:                         <Metric Name="MaintainabilityIndex" Value="100" />
 280:                         <Metric Name="CyclomaticComplexity" Value="1" />
 281:                         <Metric Name="ClassCoupling" Value="1" />
 282:                         <Metric Name="LinesOfCode" Value="1" />
 283:                       </Metrics>
 284:                     </Member>
 285:                   </Members>
 286:                 </Type>
 287:               </Types>
 288:             </Namespace>
 289:           </Namespaces>
 290:         </Module>
 291:       </Modules>
 292:     </Target>
 293:   </Targets>
 294: </CodeMetricsReport>

In coming posts we’ll analyse this XML file in a simple way and then process them in a task in Team Build

Greetings @ Home

The Bruno

   

Download: http://www.microsoft.com/downloads/en/details.aspx?FamilyID = edd1dfb0-b9fe-4e90-b6a6-5ed6f6f6e615

2 thoughts on “[TEAMBUILD2010] HowTo: Add results of analysis of code metrics in a Build (I)

  1. Pingback: [TFS2010] TFS Build Extensions Released !!! (sigue siendo complicado) | El Bruno

  2. Pingback: [TFS2010] TFS Build Extensions Released !!! (sigue siendo complicado) - El Bruno

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s