dotnet_diagnostics 和 dotnet_style_、csharp_ 等下的等效规则有什么区别?

发布于 2025-01-10 21:59:25 字数 315 浏览 3 评论 0原文

例如,在 .editorconfig 中,我可以使用两者要求字段为只读:

# IDE0044: Make field readonly
dotnet_diagnostic.IDE0044.severity = warning

并且

dotnet_style_readonly_field = true:warning

两者都会显示在编辑器中,两者都会导致问题在运行 dotnet format 时得到解决>。这两个选项有什么区别?

For example, in .editorconfig I can require fields to be readonly using both:

# IDE0044: Make field readonly
dotnet_diagnostic.IDE0044.severity = warning

and

dotnet_style_readonly_field = true:warning

Both will show up in the editor, both will cause the issue to be fixed upon running dotnet format. What are the differences between both options?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

岁月无声 2025-01-17 21:59:25

之前的答案并不完全正确,因为它在外部缺少EnforceCodeStyleInBuild = true设置>.editorconfig,但是答案要复杂得多,请参阅这篇文章。

在实践中,您必须考虑要执行什么规则、您拥有什么 IDE 以及这些 IDE 的版本、是否有 CI/CD 等。

The previous answer is not completely correct, because it is missing EnforceCodeStyleInBuild = true setup outside .editorconfig, but the answer has much more complexity, see this article.

In practice, you have to consider what rule you want to enforce, what IDEs and what version of those IDEs you have, if you have CI/CD etc.

叫思念不要吵 2025-01-17 21:59:25

编译器不知道 option = value:severity 语法,例如:

dotnet_style_readonly_field = true:warning

因此,如果您使用该语法,构建将仅针对 IDE 实时分析生成警告/错误。但是,如果您想在构建时强制执行代码样式,则需要使用 dotnet_diagnostic.RuleId.severity = Senior 语法。

The compiler is not aware of the option = value:severity syntax, e.g:

dotnet_style_readonly_field = true:warning

So if you use that, the build will produce warnings/errors only for IDE live analysis. But if you want to enforce code-style on build, you need to use the dotnet_diagnostic.RuleId.severity = severity syntax.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文