views:

2821

answers:

5

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.

+2  A: 

To my knowledge, FxCop 1.35 and onwards use two sources for the dictionary.

  • The Microsoft Office dictionary (adding words via MS Word etc. should work)
  • A 'CustomDictionary.xml' file stored in the FxCop program folder, rather than the project file folder.
andypaxo
I tried the Microsoft Office dictionary. It didn't work.
Garth T Kidd
+9  A: 

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.

spinodal
CodeAnalysisDictionary triggers a “Property value is not valid.” error on my system.
Garth T Kidd
Damien
this is probably only for vs2010
Cohen
I believe that this is actually for Team System not Professional.
John Gietzen
+9  A: 

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.

David Schmitt
I think you mean to say "put it in your project folder" not "put it in your solution folder".
mhenry1384
No, FxCop searches the project folder's parent directories. So putting the custom dictionary into the solution folder, shares the entries with all projects.
David Schmitt
Thanks! I'll test this as soon as I get time.
Thomas Bratt
A: 

Further to David Schmitt's answer above, you may need to alter/remove the custom dictionary that ships with FxCop from within the FxCop installation folder.

I've just installed FxCop v1.36, and couldn't get the Project specific words in my dictionary to be recognised until I removed the custom dictionary at C:\Program Files\Microsoft FxCop 1.36\CustomDictionary.xml.

Once, I'd moved that to one side, FxCop started using the CustomDictionary.xml in the solution folder.

This does beg the question of how to add common words to a shared custom dictionary and project/solution specific words within other custom dictionaries and actually having FxCop use both. But for now it's working....

Grhm
Thanks! I'll test this as soon as I get time.
Thomas Bratt
A: 

I am running FxCopCmd.exe as part of my build process, and here I pass the dictionary command line parameter

FxCopCmd.exe ... /dictionary:FxCopDictionary.xml

This work with the visual studio 2010 RC version of FxCop. Don't know if it'll work with previous versions.

Pete