How can I run select FxCop rules using the command line?

4.4k Views Asked by At

I know you can create a project and use relative paths, but I don't want to keep the project file in version control. Let's say for the sake of brevity that I only want to run one rule, CA1001, from Microsoft.Design. How can I specify this with command line arguments and make it work in a TeamCity FxCop build runner?

2

There are 2 best solutions below

7
Nicole Calinoiu On BEST ANSWER

There is a /ruleid command line option that can be used for this. It doesn't show up in the MSDN help topic for the fxcopcmd.exe command line options, but you can see a description by running fxcopcmd.exe /?.

0
Khushbu On

The tool is located in \FxCopCmd.exe. A list of options can be found here. All options must be appended with a colon and the parameter (if any), but with no whitespaces. A basic command looks as follows.

FxCopCmd.exe /file:E:\My\Project\Precompiled\bin 

/rule:"C:\Program Files (x86)\Microsoft FxCop 1.35\Rules" /out:fxcopreport.xml

You can also apply multiple rules like whatever needed :

"C:\Program Files\Microsoft FxCop 1.35\FxCopCmd.exe"
/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\DesignRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\GlobalizationRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\InteroperabilityRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\MobilityRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\NamingRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\PerformanceRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\PortabilityRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\SecurityRules.dll"

/rule:"C:\Program Files\Microsoft FxCop 1.35\Rules\UsageRules.dll"

/out:fxcopreport.xml

/summary

/file:"E:\MyProject\Model\bin\Debug\MyProject.dll"

/directory:"C:\Program Files\Reference Assemblies\Microsoft\Framework
\v3.5\System.Core.dll"

In the above command, the flags are:

/rule A path to the rule dll you wish to include.

/out To which file the analysis should be saved.

/summary Makes FxCop include a summary in the report.

/file The file you wish to analyse.

/directory For some reason the project file cannot remember where the System.Core.dll is located. To avoid errors you can specify the dll like this.