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:
-
<target name="analyze" depends="your-target-that-builds-assemblies" description="Run FxCop against built assemblies">
-
-
<property name="fxcop.results.file" value="${build.dir}\fxcop-results.xml" />
-
<exec program="tools\fxcop\FxCopCmd.exe" failonerror="false">
-
<arg value="/file:${build.dir}\*.dll" />
-
<arg value="/file:${build.dir}\path\to\another\assembly\to\analyze.dll" />
-
<arg value="/forceoutput" /> <!-- create output even if no violations are found -->
-
<arg value="/ruleid:-Microsoft.Globalization#CA1300" /> <!-- an example of how to suppress rules -->
-
<arg value="/ruleid:-Microsoft.Globalization#CA1301" />
-
<arg value="/ruleid:-Microsoft.Globalization#CA1302" />
-
<arg value="/ruleid:-Microsoft.Globalization#CA1303" />
-
<arg value="/ruleid:-Microsoft.Globalization#CA1304" />
-
<arg value="/ruleid:-Microsoft.Globalization#CA1305" />
-
<arg value="/ruleid:-Microsoft.Globalization#CA1306" />
-
<arg value="/out:${build.dir}\fxcop-results.xml"" />
-
</exec>
-
</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.

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
February 22nd, 2006 at 8:16 am
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
May 11th, 2006 at 12:32 am
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! :)
June 18th, 2006 at 5:33 pm
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
December 12th, 2006 at 3:44 pm
[...] I found it initially from a link on lukemelia.com. Related:NCover + CCNet + Win2003Build Server [...]
March 24th, 2007 at 8:06 pm
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
October 16th, 2007 at 7:23 pm
@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!
October 16th, 2007 at 11:00 pm
PingBack from http://www.truewill.net/myblog/index.php/2008/03/05/cruisecontrol_net
March 5th, 2008 at 10:16 pm