Luke Melia

software dev

January 5, 2006

CruiseControl.NET and FxCop

I integrated FxCop with CruiseControl.NET and NAnt for a .NET 2.0 project today. A couple of notes that might be useful for anyone doing the same.

I copied the fxcop directory from the VS.NET folder (inside of Team Tools, I think) into my tools directory, so it will be checked in with my project.

Then I added the a target like this to my nant build script:

XML:
  1. <target name="analyze" depends="your-target-that-builds-assemblies" description="Run FxCop against built assemblies">
  2.                        
  3.                         <property name="fxcop.results.file" value="${build.dir}\fxcop-results.xml" />
  4.                         <exec program="tools\fxcop\FxCopCmd.exe" failonerror="false">
  5.                                     <arg value="/file:${build.dir}\*.dll" />
  6.                                     <arg value="/file:${build.dir}\path\to\another\assembly\to\analyze.dll" />
  7.                                     <arg value="/forceoutput" /> <!-- create output even if no violations are found -->
  8.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1300" /> <!-- an example of how to suppress rules -->
  9.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1301" />
  10.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1302" />
  11.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1303" />
  12.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1304" />
  13.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1305" />
  14.                                     <arg value="/ruleid:-Microsoft.Globalization#CA1306" />
  15.                                     <arg value="/out:${build.dir}\fxcop-results.xml"" />
  16.                         </exec>
  17.   </target>

And in your ccnet.config file, make sure you are merging the results file. Update your dashboard.config file if necessary. These changes are explained on the CC.NET Confluence site.

On my first pass with this, the output was not accounting for the violations I had suppressed in Visual Studio using the SuppressMessage attribute. The issue was that the SuppressMessage attribute is conditional. You need to define the CODE_ANALYSIS conditional compilation symbol in order for the attributes to be present in your built assemblies and therefore be noticed by FxCopCmd.exe.

Finally, if you're using FireFox instead of IE, you'll notice that the XSL presentation of the FxCop results are pretty ugly and hard to interact with. On the CruiseControl .NET Community XSL Transforms page, you'll want to grab fxcop XSLs from the Alternative Style Sheets and Templates Version 2.2, by Michael Luke. Thanks, Michael!

There's another approach, too, which is to call out to MSBuild to do the CodeAnalysis for you. You might achieve better integration with VS.NET that way. Can't speak to it, though, so you're on your own. If you take that path, leave a comment here and let me know how it turns out.

8 Responses to “CruiseControl.NET and FxCop”

  1. a gravatar Amit Kumar chimed in:

    I want to use cruisecontrol and fxcop...

    its not working. Can u plz. send me what all should i write in .build file and what all in ccnet.config file.

    Its urgent.

    Thanks
    Amit Kumar

  2. a gravatar Prabhakar chimed in:

    I too tried to use cruisecontrol with fxcop…, but don't know hoe to trigger or call the conents in the target tag
    its not working. Can u plz. send me what all should i write in .build file and what all in ccnet.config file.

    Its urgent.
    thnaks
    Prabhakar

  3. a gravatar Tim chimed in:

    Hi!

    Just wanted to say thanks for sharing this info, I've been having a few problems getting FXCop to play nicely with the CCNet process, but your example helped me find my errors and its now working nicely! :)

    Thanks for sharing! :)

  4. a gravatar Allen Sanborn chimed in:

    Integrating FxCop into your MsBuild script is VERY easy. This has the benefit of keeping your ccnet.config a little easier to read.

    From http://blogs.msdn.com/mswanson/archive/2004/10/05/238423.aspx. This page

    c:\depot\Bank\*.FxCop.xml

  5. a gravatar vorpal.cc/blog » CCNet Community XSL Transforms chimed in:

    [...] I found it initially from a link on lukemelia.com. Related:NCover + CCNet + Win2003Build Server [...]

  6. a gravatar narendra chimed in:

    i keep getting this error i dont know why

    MSB3073: The command "FxCopCmd.exe /project:C:\Projects\Main\Src\Sln\Phoenix.fxcop /out:C:\Public\BuildLogs\fxcop\Phoenix.FxCop.xml" exited with code 4. in Phoenix.msbuild(6, 5)

    when i try running it from command line manually it works

    any suggestions

  7. a gravatar lukemelia chimed in:

    @narendra: I'm not sure. From your error, it doesn't look like you are trying what I blogged about... the post shows a NAnt snippet and your error is an MSBuild error.

    Good luck!

  8. a gravatar TrueWill chimed in:

    PingBack from http://www.truewill.net/myblog/index.php/2008/03/05/cruisecontrol_net

Leave a Reply

LukeMelia.com created 1999. ··· Luke Melia created 1976. ··· Live With Passion!