1

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?

Lunyx
  • 3,164
  • 6
  • 30
  • 46

2 Answers2

1

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 /?.

Nicole Calinoiu
  • 20,843
  • 2
  • 44
  • 49
  • Based on the example rule I provided, how would you format it as per the documentation? `/ruleid:<[+|-]Namespace.CheckId|Category#CheckId>` – Lunyx Sep 10 '14 at 21:12
  • `fxcopcmd.exe /rule:"-\DesignRules.dll" /ruleid:"+Microsoft.Design#CA1001" /file:""` – Nicole Calinoiu Sep 11 '14 at 14:02
  • Is this actually supported? I tested it in the syntax you described, but it still runs all of the rules within Microsoft.Design. – Lunyx Sep 16 '14 at 21:19
  • I'm thinking that it might be that since DesignRules.dll is already specified, it will run everything in there and we have to remove all of the other rules first before adding the one we want. That seems like it'd be a massive pain to write out. – Lunyx Sep 16 '14 at 21:28
  • Seems like I was right. However, I could not remove all ruleids with a wildcard. Not really sure what the best approach is at this point. – Lunyx Sep 16 '14 at 21:49
  • Did you add the minus sign at the start of the path to DesignRules.dll? – Nicole Calinoiu Sep 17 '14 at 13:32
  • I missed that. I ended up just creating a ruleset file and checking that in instead since it's easy to maintain and will more easily allow for additional rules to be added rather than editing a command line. However, your answer does do what my question asked, so I have accepted it. – Lunyx Sep 17 '14 at 14:40
0

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.

Abhinav Singh Maurya
  • 3,313
  • 8
  • 33
  • 51