简体   繁体   English

如何抑制整个命名空间文件的StyleCop警告

[英]How to suppress a StyleCop warning of entire namespace files

I'm using Style Cop version 4.7. 我正在使用Style Cop版本4.7。 Global suppression don't work for every member of selected namespace. 全局抑制不适用于所选命名空间的每个成员。

I have two files in the same namespace (StyleCopSample.Test). 我在同一名称空间中有两个文件(StyleCopSample.Test)。 When I set suppress message in the first file, messages are suppressing only for this file, but the second file still gets a warnings. 当我在第一个文件中设置抑制消息时,消息仅抑制此文件,但第二个文件仍会收到警告。

Content of the first file: 第一个文件的内容:

[assembly: SuppressMessage("CSharp.DocumentationRules", "*", Scope = "Namespace", Target = "StyleCopSample.Test")]

namespace StyleCopSample.Test
{
  class TestFirst {}
}

Content of the second file: 第二个文件的内容:

namespace StyleCopSample.Test
{
  class TestSecond {}
}

I don't want to describe suppress message attribute for every physical file of the same namespace. 我不想为同一命名空间的每个物理文件描述抑制消息属性。 Any ideas? 有任何想法吗?

Thanks for Your time! 谢谢你的时间!

I think it's better just to disable the documentation rules on the StyleCop settings file. 我认为最好只禁用StyleCop设置文件中的文档规则。

Just open the settings dialog from the project context menu. 只需从项目上下文菜单中打开设置对话框即可。

菜单项

And then uncheck the 'Documentation Rules' checkbox. 然后取消选中“文档规则”复选框。

取消选中此项

The SuppressMessage directive will only process the current file (see the comments in this stylecop issue ). SuppressMessage指令仅处理当前文件(请参阅此stylecop问题中的注释)。

You could possibly achieve what you want via file lists , although this will work best if there are only a few files you want to apply this exclusion to. 您可以通过文件列表实现所需的功能 ,但如果只有少数文件要应用此排除项,则最有效。 If you want this applied to all files in a particular project, then the easiest way may be to simply modify the settings via the settings dialog as already mentioned. 如果您希望将此应用于特定项目中的所有文件,则最简单的方法可能是通过设置对话框简单地修改设置,如前所述。

Alternatively, you could put all the namespace related files into a separate folder, and have a custom settings file in that folder to exclude these rules from those particular files. 或者,您可以将所有与命名空间相关的文件放入单独的文件夹中,并在该文件夹中具有自定义设置文件,以从这些特定文件中排除这些规则。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM