【问题标题】:How to specify Suppress​Message​Attribute.​Check​Id for .NET Standard Class Library?如何为 .NET Standard 类库指定 Suppress​Message​Attribute.​Check​Id?
【发布时间】:2021-12-29 02:47:39
【问题描述】:

我正在 VS2017 上编写一个 .NET Standard 2.0 类库。在错误列表中,我收到了一些消息,例如:

IDE0018 变量声明可以内联

我可以取消警告via the context menu

它在我的项目中创建了一个GlobalSuppressions.cs

using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "<Pending>", Scope = "member", Target = "~M:SomeType.SomeMethod()~System.Int32")]

我想禁止所有像IDE1006 这样的消息,所以我将其修改为

using System.Diagnostics.CodeAnalysis;
[assembly: SuppressMessage("Style", "IDE1006:Naming Styles")]

现在我想手动抑制IDE1008 等,但我不知道IDE1008 的标准描述是什么。 [assembly: SuppressMessage("Style", "IDE1008:???")]

我可以在Analyzing Application Quality by Using Code Analysis Tools 中找到一些CA1234 警告定义。

所以我的问题是:IDE1234这样的IDE消息的定义在哪里

【问题讨论】:

    标签: c# code-analysis


    【解决方案1】:

    Nathen Silver's answer 可能是最有用的,但我想直接回答问题:

    所以我的问题是:IDE1234等IDE消息的定义在哪里?

    之前可能不是这样,但您可以在 MSDN (docs.microsoft.com) 上找到 IDE 消息的定义。对于您看到的具体错误消息IDE0008

    https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0007-ide0008

    页面包含生成属性所需的一切:

    规则 ID:IDE0007 和 IDE0008

    标题:IDE0007:使用 'var' 而不是显式类型 IDE0008:使用显式类型而不是 'var'

    类别:风格

    我发现您通常可以将 IDE 编号放在末尾 (https://docs.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/ide0008),然后您将被链接到正确的页面。

    【讨论】:

      【解决方案2】:

      我没有找到 IDE 消息的定义列表,但您不需要样式的标准描述来隐藏它。

      你可以这样做:

      [assembly: SuppressMessage("Style", "IDE1008")]
      

      【讨论】:

        猜你喜欢
        • 2018-06-23
        • 1970-01-01
        • 1970-01-01
        • 2023-03-06
        • 2017-05-10
        • 1970-01-01
        • 2017-07-04
        • 1970-01-01
        • 2019-06-01
        相关资源
        最近更新 更多