Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the FxCop custom dictionary to work?

How is it possible to get the FxCop custom dictionary to work correctly?

I have tried adding words to be recognised to the file 'CustomDictionary.xml', which is kept in the same folder as the FxCop project file. This does not seem to work, as I still get the 'Identifiers should be spelled correctly' FxCop message, even after reloading and re-running FxCop. Using version 1.36.

like image 610
Thomas Bratt Avatar asked Dec 11 '08 13:12

Thomas Bratt


People also ask

What is Microsoft's FxCop?

Microsoft's FxCop is a free static code analysis tool that checks your assemblies for compliance against some built-in rules. You can also develop custom rules and run FxCop to check for compliance of the assemblies against such defined standards.

How do I view all the rules provided by FxCop?

All rules provided by FxCop are categorized under Breaking or Non-Breaking. Click on the Analyze button in the toolbar while doing so shows a progress bar, and then fills the message pane with all the messages it found. On top of the pane, you see three buttons – Active, Excluded and Absent.

How do I set up FxCop in Visual Studio?

To set up FxCop as an external tool in Visual Studio: On the Tools menu, click External Tools, and then click Add. Enter the following information in External Tools dialog box: Title: FxCop. Command: C:Program FilesMicrosoft FxCop 1.36FxCopCmd.exe.

What is the difference between a rule and a target in FxCop?

In FxCop, a rule is a defined standard against which the FxCop engine would inspect an assembly to check for compliance or adherence to the defined standards. A target in FxCop refers to the managed assembly that would be analyzed by FxCop to check for compliance to the defined standards.


2 Answers

If you use it inside Visual Studio...

From Visual Studio Code Analysis Team Blog

To add a custom dictionary to a C# and Visual Basic project is simple:

  1. In Solution Explorer, right-click on the project and choose Add -> New Item...
  2. Under Templates, select XML File, enter a name for the dictionary, such as CodeAnalysisDictionary.xml and click Add
  3. In Solution Explorer, right-click on the XML file and choose Properties
  4. In the Properties tool window, under Build Action choose CodeAnalysisDictionary
  5. In Solution Explorer, double-click on the newly created dictionary to open it
  6. In the XML editor, paste the following, replacing "productname" and "companyname" with your team's equivalents:

    <Dictionary>      <Words>         <Recognized>             <Word>"productname"</Word>             <Word>"companyname"</Word>         </Recognized>     </Words> </Dictionary> 

You are now ready to start entering your own custom words. Simply add a new element for each word in your project that does not exist in the dictionary. Each word is case-insensitive, so any casing of the word will be recognized. Code Analysis will automatically pick up the custom dictionary the next time it is run.

like image 99
spinodal Avatar answered Sep 23 '22 03:09

spinodal


The easiest way is to just call it "CustomDictionary.xml" and put it in your solution folder, where FxCop (1.36 tested here) will pick it up automatically, if you have

<CustomDictionaries SearchFxCopDir="True"                     SearchUserProfile="True"                     SearchProjectDir="True" /> 

in your FxCop project file.

Alternatively you can specify it via the /dictionary command line parameter.

like image 32
David Schmitt Avatar answered Sep 24 '22 03:09

David Schmitt