c# - 整个命名空间的“SuppressMessage”

标签 c# .net namespaces code-analysis fxcop

我在测试方法中使用下划线以提高可读性,并且我想抑制整个测试命名空间的 FxCop 错误/警告。

我怎样才能做到这一点?我玩过 GlobalSuppressions.cs 但没有任何效果:

[module: System.Diagnostics.CodeAnalysis.SuppressMessage(
    "Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",
    Scope = "namespace", Target = "Company.Product.Tests")]

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
    "Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",
    Scope = "namespace", Target = "Company.Product.Tests")]

最佳答案

自 Visual Studio 2019 以来,可以抑制命名空间及其所有后代符号的代码分析警告:

[assembly: System.Diagnostics.CodeAnalysis.SuppressMessage(
    "Microsoft.Naming", "CA1707:IdentifiersShouldNotContainUnderscores",
    Justification = "Test methods require underscores for readability."
    Scope = "namespaceanddescendants", Target = "Company.Product.Tests")]

Scope - The target on which the warning is being suppressed. If the target is not specified, it is set to the target of the attribute. Supported scopes include the following:

  • ...

  • namespaceanddescendants - (New for Visual Studio 2019) This scope suppresses warnings in a namespace and all its descendant symbols. The namespaceanddescendants value is only valid for Roslyn analyzers, and is ignored by binary, FxCop-based static analysis.

Suppress code analysis warnings#SuppressMessage attribute @ MS Docs

关于c# - 整个命名空间的“SuppressMessage”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11359652/

相关文章:

Ruby 命名空间问题

c# - 无法 nunit 测试我的 log4net 包装类

c# - WPF 转 jpg/gif/png/svg

c# - 管理 CheckedListBox ItemCheck 事件以在检查项目之后而不是之前运行

c# - x64 系统上的 x86 应用程序使用哪个 ngen?

C# 将多个参数传递给 BAT 文件

javascript - 通过 jest (ts-jest) 使用命名空间测试 typescript 代码

c# - div 位置内的图像按钮

c# - 异步表达式C#

css - 可扩展的全局变量赋值@mixin for Sass