【问题标题】:Suppressing StyleCop errors from the string in resource从资源中的字符串中抑制 StyleCop 错误
【发布时间】:2011-05-26 15:52:48
【问题描述】:

我得到了几十个 CA1703:Microsoft.Naming error

resource Resources.resx', referenced by name 'code', correct the spelling of 
'addfile' in string value '#set ...'

这很荒谬,因为 StyleCop 对代码运行拼写检查以产生拼写错误。

如何抑制这个 StyleCop 错误?

我尝试使用此提示中的 SuppressMessage,但我再次收到错误 - Error 70 The type or namespace name 'SuppressMessageAttribute' could not be found (are you missing a using directive or an assembly reference?)

[SuppressMessage("Microsoft.StyleCop.CSharp.DocumentationRules", "CA1703:Microsoft.Naming", Justification = "This is tcl script, spelling check is meaningless")] 
        public static void Generate(string clientDirectory, string topLevelTestbench, string doFileName)

【问题讨论】:

    标签: .net visual-studio visual-studio-2010 stylecop


    【解决方案1】:

    CA1703 是 FxCop 规则,而不是 StyleCop 规则。由于您似乎不知道您正在使用 FxCop,我猜您正在使用与某些 Visual Studio 版本集成的代码分析版本。如果是这样,您只需右键单击 Visual Studio 错误列表中的问题,然后选择 Suppress Message(s) -> In Project Suppression File 上下文菜单项以自动添加正确填充的 SuppressMessage 属性资源文件中的问题。 (仅使用指令添加 System.Diagnostics.CodeAnalysis 是不够的,因为示例属性实例中的类别和检查 ID 对于 CA1703 规则都不正确。)

    【讨论】:

      【解决方案2】:

      你是否使用了正确的 using 指令:

      using System.Diagnostics.CodeAnalysis;
      

      要确保它可以找到 SuppressMessage 类?

      【讨论】:

        【解决方案3】:

        正如 Nicole Calinoiu 所说,这是 FxCop 规则。这是规则说明http://msdn.microsoft.com/en-us/library/bb264483.aspx您可以轻松地将单词添加到您自己的字典中,以避免出现 FxCop 不知道的单词错误(例如您的公司名称或一些技术单词),请参阅http://msdn.microsoft.com/en-us/library/bb264492.aspx

        【讨论】: