Code Analysis for Visual Studio 2010 Pro - via FxCop from the command line

problem:
the Pro version of Visual Studio 2010 is missing the Code Analysis (Fx Cop) feature.

workaround:
some smart folks have figured out a way to install the latest version of FxCop:

http://blogx.co.uk/Comments.asp?Entry=812

see also:
http://stackoverflow.com/questions/2740738/fxcop-for-net-4-0

using FxCop on the command line
Once you have FxCop installed, you can then use it from the command line, to perform static code analysis of your assembly files.

example scripts
here are some simple scripts I use, to analyse the assemblies I am working on:


run_fxcop_on_assembly.bat
 @ECHO OFF  
 SETLOCAL  
 SET PATH_TO_ASM=%1  
 SET REPORT_OUT_PATH=%TEMP%\FxCopCmd_report.xml  
 pushd "c:\Program Files\Microsoft Fxcop 10.0"  
 FxCopCmd.exe /f:%PATH_TO_ASM% /out:%REPORT_OUT_PATH%  
 ECHO opening report in XML handler (iexplore is good for this!):  
 %REPORT_OUT_PATH%  
 popd  
 ECHO Finding Dead code...  
 call fxCopResults_FindDeadCode.bat  


fxCopResults_FindDeadCode.bat
 type %TEMP%\FxCopCmd_report.xml | Find "is never used"  

usage:
 run_fxcop_on_assembly.bat c:\sourceroot\MyProject\bin\Release\MyAssembly.exe 

be warned: reading the results of FxCop can be a humbling experience !!

FxCop results:
below is a screenshot of the results file, opened in Internet Explorer:
(the results file is an XML file with a built in XSL stylesheet, for nice presentation)


Comments