How to get the FxCop custom dictionary to work?

2019-01-23 00:43发布

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.

8条回答
Root(大扎)
2楼-- · 2019-01-23 01:09

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

查看更多
对你真心纯属浪费
3楼-- · 2019-01-23 01:10

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.

查看更多
叛逆
4楼-- · 2019-01-23 01:11

I didn't have to set Build Action to be CodeAnalysisDictionary. In fact, I didn't even have that as an option (using Visual Studio 2010 Professional). I'm using the FxCop Integrator extension. It allows you to right-click on the Solution and choose Code Analysis. The other option is More Tasks. Within that More Tasks menu is the ability to edit Edit FxCop Dictionary. When I performed the edit, it created a new Solution Folder called Code Analysis containing a new XML file called FxCopDictionary.xml. This XML file is set up as one would expect the CustomDictionary.xml file to look like.

Hope this helps someone out there!

查看更多
男人必须洒脱
5楼-- · 2019-01-23 01:13

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.
查看更多
时光不老,我们不散
6楼-- · 2019-01-23 01:19

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.

查看更多
可以哭但决不认输i
7楼-- · 2019-01-23 01:24

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.

查看更多
登录 后发表回答