dotnet_diagnostics 和 dotnet_style_、csharp_ 等下的等效规则有什么区别?
例如,在 .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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
之前的答案并不完全正确,因为它在
外部缺少
,但是答案要复杂得多,请参阅这篇文章。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.
编译器不知道
option = value:severity
语法,例如:因此,如果您使用该语法,构建将仅针对 IDE 实时分析生成警告/错误。但是,如果您想在构建时强制执行代码样式,则需要使用
dotnet_diagnostic.RuleId.severity = Senior
语法。The compiler is not aware of the
option = value:severity
syntax, e.g: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.