{"id":823,"date":"2011-01-29T11:32:00","date_gmt":"2011-01-29T11:32:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/buckh\/2011\/01\/29\/code-metrics-command-line-tool\/"},"modified":"2011-01-29T11:32:00","modified_gmt":"2011-01-29T11:32:00","slug":"code-metrics-command-line-tool","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/buckh\/code-metrics-command-line-tool\/","title":{"rendered":"Code metrics command line tool"},"content":{"rendered":"<p><a href=\"http:\/\/blogs.msdn.com\/b\/camerons\/\"><\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/camerons\/\"><\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/camerons\/\"><\/a><\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/camerons\/\"><\/a><\/p>\n<p><strong>[UPDATE 3\/24\/12]<\/strong> &nbsp;You can find a real code metrics activity&nbsp;<a href=\"http:\/\/tfsbuildextensions.codeplex.com\/wikipage?title=How%20to%20integrate%20the%20codemetric%20build%20activity&amp;referringTitle=Documentation\">here<\/a>&nbsp;as part of the <a href=\"http:\/\/tfsbuildextensions.codeplex.com\/\">Community TFS Build Extensions<\/a>.<\/p>\n<p><a href=\"http:\/\/blogs.msdn.com\/b\/camerons\/\">Cameron Skinner<\/a> has announced a new <a href=\"http:\/\/blogs.msdn.com\/b\/camerons\/archive\/2011\/01\/28\/code-metrics-from-the-command-line.aspx\">command line tool for generating code metrics<\/a>.&nbsp; We&rsquo;ve long gotten requests to be able to generate code metrics from the build.&nbsp; Prior to this tool, code metrics could only be generated from within the Visual Studio IDE.<\/p>\n<p>I installed it this morning.&nbsp; The <a href=\"http:\/\/www.microsoft.com\/downloads\/info.aspx?na=46&amp;SrcFamilyId=EDD1DFB0-B9FE-4E90-B6A6-5ED6F6F6E615&amp;SrcDisplayLang=en&amp;u=http%3a%2f%2fdownload.microsoft.com%2fdownload%2f9%2f5%2fD%2f95D36B12-7581-4C54-9FC4-9CAFAB819B98%2freadme.txt\">readme link<\/a> on the download page tells you where it is installed, which is %programfiles%\\Microsoft Visual Studio 10.0\\Team Tools\\Static Analysis Tools\\FxCop.<\/p>\n<p>I wanted to do the simplest possible thing (i.e., quick and dirty!) I could to give it a try this morning as part of a 2010 TFS build.&nbsp; I grabbed the copy of <a href=\"http:\/\/www.amazon.com\/Professional-Application-Lifecycle-Management-Programmer\/dp\/0470484268\/ref=sr_1_1?ie=UTF8&amp;qid=1296330915&amp;sr=8-1\">Professional Application Lifecycle Management<\/a> I happened to have sitting here on my desk at home (thanks, <a href=\"http:\/\/woodwardweb.com\/\">Martin<\/a>) and turned to page 504 to follow the ZIP archive example to get me started.&nbsp; You can get the <a href=\"http:\/\/media.wiley.com\/product_data\/excerpt\/68\/04704842\/0470484268-2.pdf\">entire build chapter<\/a> for free (same with the <a href=\"http:\/\/media.wiley.com\/product_data\/excerpt\/68\/04704842\/0470484268-1.pdf\">manual testing chapter<\/a>).<\/p>\n<ol>\n<li>Open up the default build process template in the WF designer (e.g., open the build definition, click Show Details on the Process tab, click on the hyperlink, and double click the file)<\/li>\n<li>Scroll to the bottom of the workflow.<\/li>\n<li>Drag an <a href=\"https:\/\/blogs.blackmarble.co.uk\/blogs\/rfennell\/archive\/2010\/02\/23\/logging-results-from-invokeprocess-in-a-vs2010-team-build.aspx\">InvokeProcess<\/a> activity into the build process.&nbsp; Drop it in as the last activity in the Try, Compile, Test sequence (drop it after the symbol activity, just before the catch block).<\/li>\n<li>Right click on the InvokeProcess activity and show parameters<\/li>\n<li>Set the following properties, fixing up the paths for your machine and the hard-coded assembly name (like I said, I went for the quick and dirty just to see it work).\n<ol>\n<li>Arguments: String.Format(&#8220;\/f:&#8221;&#8221;{0}&#8221;&#8221; \/o:&#8221;&#8221;{1}&#8221;&#8221;&#8221;, System.IO.Path.Combine(BinariesDirectory, &#8220;ConsoleApplication1.exe&#8221;), System.IO.Path.Combine(BinariesDirectory, &#8220;out.xml&#8221;))<\/li>\n<li>DisplayName: Code Metrics<\/li>\n<li>FileName: &#8220;D:\\Program Files (x86)\\Microsoft Visual Studio 10.0\\Team Tools\\Static Analysis Tools\\FxCop\\metrics.exe&#8221;<\/li>\n<\/ol>\n<\/li>\n<li>Drop a WriteBuildMessage into the bock for the standard output and a WriteBuildError for the error output.<\/li>\n<li>Set the following for WriteBuildMessage\n<ol>\n<li>Importance: Microsoft.TeamFoundation.Build.Client.BuildMessageImportance.High<\/li>\n<li>Message: stdOutput<\/li>\n<\/ol>\n<\/li>\n<li>Set the following for the WriteBuildError\n<ol>\n<li>Message: errOutput<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n<p>Then I checked in my build template changes and ran a build.&nbsp; The drop folder now contains a file called <span style=\"font-family: 'Courier New'\">out.xml<\/span> with the code metric data in it.<\/p>\n<p>You can find documentation on all of the activities <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/gg433940.aspx\">here<\/a> on MSDN.<\/p>\n<p>Enjoy!<\/p>\n<p><strong>[UPDATE 1\/30\/10]<\/strong>&nbsp; Martin sent me the links to the build and testing chapters, which I&rsquo;ve added above.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>[UPDATE 3\/24\/12] &nbsp;You can find a real code metrics activity&nbsp;here&nbsp;as part of the Community TFS Build Extensions. Cameron Skinner has announced a new command line tool for generating code metrics.&nbsp; We&rsquo;ve long gotten requests to be able to generate code metrics from the build.&nbsp; Prior to this tool, code metrics could only be generated from [&hellip;]<\/p>\n","protected":false},"author":94,"featured_media":10268,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[7,8,11],"class_list":["post-823","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","tag-team-build","tag-team-foundation","tag-tfs-2010"],"acf":[],"blog_post_summary":"<p>[UPDATE 3\/24\/12] &nbsp;You can find a real code metrics activity&nbsp;here&nbsp;as part of the Community TFS Build Extensions. Cameron Skinner has announced a new command line tool for generating code metrics.&nbsp; We&rsquo;ve long gotten requests to be able to generate code metrics from the build.&nbsp; Prior to this tool, code metrics could only be generated from [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/823","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/users\/94"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/comments?post=823"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/posts\/823\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media\/10268"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/media?parent=823"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/categories?post=823"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/buckh\/wp-json\/wp\/v2\/tags?post=823"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}