jpoh
jpoh

Reputation: 4606

FxCop taking issue with my use of format strings in resources with NON-Team System Visual Studio

I ran FxCop on one of the projects that I am working on and I got a whole slew of warnings that look like the following:

CA1703 : Microsoft.Naming : In resource 'MyProject.Properties.Resources.resx', referenced by name 'MyString', correct the spelling of 'Myyyy' in string value 'Some format string: {0:dMMMyyyy}'

As Resources is a generated class, I can't simply suppress these messages using the normal mechanism. Does anyone have any bright ideas how I can get around this problem?

Edit: Just to make things clear (as I wasn't aware that this was any different with Team System), I am interested in non- Team System solutions - in particular for MS Visual Studio Pro 2008.

Upvotes: 3

Views: 1717

Answers (4)

jpoh
jpoh

Reputation: 4606

I ended up disabling spell-checking for resources by setting the Neutral Language of the assembly to nothing i.e. in AssemblyInfo.cs, I have this line added:

[assembly: NeutralResourcesLanguage("")]

This is as suggested here.

Upvotes: 3

Scott Dorman
Scott Dorman

Reputation: 42516

FxCop (stand-alone) and the integrated Code Analysis both support the use of a custom dictionary.

Create a file that is named CustomDictionary.xml. Add the following XML structure, with the new words (case insensitive) under the node.

<Dictionary>
    <Words>
        <Recognized>
               <Word>aNewWord</Word>
               <Word>AnotherNewWord</Word>
        </Recognized>
    </Words>
</Dictionary>

To use the dictionary with all projects, put the file in the FxCop install directory (usually C:\Program Files\Microsoft FxCop). For project-specific dictionaries, put the file in a separate directory together with the project file. For the words to be recognized, you must close and restart FxCop after you create or modifying the custom dictionary. You can also include the file in a Visual Studio project and set the Build Action file property to CodeAnalysisDictionary.

Upvotes: 1

Stefan Steinegger
Stefan Steinegger

Reputation: 64638

If you don't want to have naming rules applied to resources, just turn off this rule in the project settings.

  1. Right click on the project in the project tree
  2. Click "Properties"
  3. Go to the tab "Code Analysis"
  4. Expand the branch "Naming Rules"
  5. Disable CA1703

If you just want to suppress certain resources, you can suppress them in the global suppression file. This is normally available on the right mouse key in the Error List of visual studio.

  1. Right click on the CA message(s) in the Error List
  2. Choose "Suppress Messages(s)"
  3. Choose "In Project Suppression File"

Upvotes: 3

R. Martinho Fernandes
R. Martinho Fernandes

Reputation: 234654

Instead of turning off the rule for the whole project, or manually excluding all the violations, you can turn off analysis of generated code, under:

Project > Options > Spelling & Analysis
Check Suppress analysis results against generated code

Upvotes: 1

Related Questions