从资源中的字符串中抑制StyleCop错误

时间:2011-05-26 15:52:48

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

我收到了数十个CA1703:Microsoft.Naming错误

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)

3 个答案:

答案 0 :(得分:3)

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

答案 1 :(得分:2)

您使用的是正确的使用指令:

using System.Diagnostics.CodeAnalysis;

确保它可以找到SuppressMessage类?

答案 2 :(得分:0)

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

相关问题