简体   繁体   English

无法在 Rider 中抑制 CA1307 警告

[英]Can't suppress CA1307 warning in Rider

We have an .editorconfig file which has coding style requirements for all our projects.我们有一个.editorconfig文件,它具有我们所有项目的编码风格要求。 Part of the team use Rider, another part use VS.一部分团队使用 Rider,另一部分使用 VS。 I'm trying to suppress CA1307 warning like this:我试图像这样抑制 CA1307 警告:

dotnet_diagnostic.CA1307.severity = none

Visual Studio recognizes it just fine, but Rider still shows this as a warning. Visual Studio 可以很好地识别它,但 Rider 仍然将其显示为警告。 It's getting suppressed though when I'm using它在我使用时被抑制了

#pragma warning disable CA1307

and such weird behavior is only with this particular rule, other work ok.这种奇怪的行为仅适用于此特定规则,其他工作正常。 Is there something special about it or am I doing something wrong?它有什么特别之处还是我做错了什么?

I figured what's the problem was so want to share my findings in case someone will run across the same issue.我想出了问题所在,所以想分享我的发现,以防有人遇到同样的问题。 It appears that this rule and some other, like 1304, 1305, 1309, 1311 etc. are global, and therefore cannot be suppressed in.editorconfig.看起来这条规则和其他一些规则,如 1304、1305、1309、1311 等是全局的,因此不能在 .editorconfig 中被抑制。 There are multiple ways to do it though:虽然有多种方法可以做到这一点:

  1. <NoWarn>1304,1305...</NoWarn> in.csproj file <NoWarn>1304,1305...</NoWarn> .csproj文件中

  2. Adding.globalconfig file along with.editorconfig添加 .globalconfig 文件和 .editorconfig

     is_global = true do.net_diagnostic.CA1304.severity = none do.net_diagnostic.CA1305.severity = none do.net_diagnostic.CA1307.severity = none do.net_diagnostic.CA1309.severity = none do.net_diagnostic.CA1311.severity = none

Bad thing about these 2 options is that they work just fne in VS, but Rider does not support both and keeps highlighting these warnings (they have pending tickets for this, but still not fixed).这 2 个选项的坏处是它们在 VS 中工作得很好,但 Rider 不支持这两个选项并不断突出显示这些警告(他们为此有未决的票证,但仍未修复)。 So, because we share these settings and devs are using both Rider and VS, I ended up wit option因此,因为我们共享这些设置并且开发人员同时使用 Rider 和 VS,所以我最终选择了机智

  1. GlobalSuppressions.cs file. GlobalSuppressions.cs 文件。 It has to be placed in the root of the project and looks like this:它必须放在项目的根目录中,如下所示:

     using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Globalization", "CA1304:Specify CultureInfo", Justification = "Not needed in context of our projects", Scope = "module")] [assembly: SuppressMessage("Globalization", "CA1311:Specify a culture or use an invariant version", Justification = "Not needed in context of our projects", Scope = "module")] [assembly: SuppressMessage("Globalization", "CA1305:Specify IFormatProvider", Justification = "Not needed in context of our projects", Scope = "module")] [assembly: SuppressMessage("Globalization", "CA1307:Specify StringComparison", Justification = "Not needed in context of our projects", Scope = "module")] [assembly: SuppressMessage("Globalization", "CA1309:Use ordinal StringComparison", Justification = "Not needed in context of our projects", Scope = "module")]

This way it works both in Rider and VS.这样它在 Rider 和 VS 中都可以工作。 Hope it'll help someone.希望它能帮助别人。

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

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