FxCop 对我在非团队系统 Visual Studio 的资源中使用格式字符串提出了疑问

发布于 2024-07-30 11:44:09 字数 435 浏览 3 评论 0原文

我在我正在从事的一个项目上运行了 FxCop,收到了大量如下所示的警告:

CA1703:Microsoft.Naming:在 资源 'MyProject.Properties.Resources.resx', 通过名称“MyString”引用, 更正“Myyyy”的拼写 字符串值'某些格式字符串: {0:dMMMyyyy}'

由于 Resources 是一个生成的类,因此我不能简单地使用正常机制来抑制这些消息。 有谁有什么好主意如何解决这个问题?

编辑:为了澄清这一点(因为我不知道这与 Team System 有什么不同),我对非 Team System 解决方案感兴趣 - 特别是 MS Visual Studio Pro 2008。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

心作怪 2024-08-06 11:44:09

如果您不想将命名规则应用于资源,只需在项目设置中关闭此规则即可。

  1. 右键单击项目树中的项目
  2. 单击“属性”
  3. 转到选项卡“代码分析”
  4. 展开分支“命名规则”
  5. 禁用 CA1703

如果您只想抑制某些资源,可以在全局抑制文件中抑制它们。 通常可以通过 Visual Studio 的错误列表中的鼠标右键找到此信息。

  1. 右键单击错误列表中的 CA 消息
  2. 选择“抑制消息”
  3. 选择“在项目抑制文件中”

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"
迷乱花海 2024-08-06 11:44:09

我最终通过将程序集的中性语言设置为空来禁用资源的拼写检查,即在 AssemblyInfo.cs 中添加了这一行:

[assembly: NeutralResourcesLanguage("")]

这是建议的 此处

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.

剪不断理还乱 2024-08-06 11:44:09

您可以在以下位置关闭对生成代码的分析,而不是关闭整个项目的规则或手动排除所有违规行为:

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

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
淑女气质 2024-08-06 11:44:09

FxCop(独立)和集成代码分析都支持使用自定义字典。

创建一个名为 CustomDictionary.xml 的文件。 添加以下 XML 结构,并在节点下添加新词(不区分大小写)。

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

要将字典用于所有项目,请将文件放入 FxCop 安装目录(通常为 C:\Program Files\Microsoft FxCop)。 对于项目特定的字典,请将文件与项目文件一起放在单独的目录中。 为了识别单词,您必须在创建或修改自定义词典后关闭并重新启动 FxCop。 您还可以将该文件包含在 Visual Studio 项目中,并将“生成操作文件”属性设置为 CodeAnalysisDictionary

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文