How to get the FxCop custom dictionary to work?

Thomas Bratt picture Thomas Bratt · Dec 11, 2008 · Viewed 13k times · Source

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.

Answer

spinodal picture spinodal · Jan 15, 2009

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.