Wednesday, 28 March 2007

Running FxCop or Code Analysis

If you're fortunate enough to have one of the Visual Studio Team editions, then you have the inbuilt Code Analysis tool that you can run.

Otherwise, you can use the free FxCop tool

But what if you're in a team with a mix of Team Edition and Professional (eg. no Code Analysis)?

Add the following to the bottom of your project files and FxCop will be run on Release builds if you don't have the inbuilt Code Analysis tool installed:

<!-- Run FxCop if available on Release builds, but not if we also have Team Developer -->

<Target Name="AfterBuild" Condition=" ('$(Configuration)' == 'Release') And Exists('$(ProgramFiles)\Microsoft FxCop 1.35') And !(Exists('$(ProgramFiles)\Microsoft Visual Studio 8\Team Tools\Static Analysis Tools\FxCop\FxCopCmd.exe'))">

<Exec Command="FxCopCmd.exe /file:&quot;$(MSBuildProjectDirectory)\$(OutputPath)$(AssemblyName).dll&quot; /out:&quot;$(MSBuildProjectDirectory)\$(OutputPath)\ccnet-fxcop.xml&quot;" WorkingDirectory="$(ProgramFiles)\Microsoft FxCop 1.35" />


1 comment:

Patrick Smacchia said...

Folks interested in FxCop might be interested by the tool NDepend:

NDepend analyses source code and .NET assemblies. It allows controlling the complexity, the internal dependencies and the quality of .NET code.

NDepend provides a language (CQL Code Query Language) dedicated to query and constraint a codebase.

It also comes from with advanced code visualization (Dependencies Matrix, Metric treemap, Box and Arrows graph...), more than 60 metrics, facilities to generate reports and to be integrated with mainstream build technologies and development tools.

NDepend also allows to compare precisely different versions of your codebase.