gpt4 book ai didi

visual-studio - 对规则集文件与 editorconfig 文件感到困惑

转载 作者:行者123 更新时间:2023-12-03 09:36:05 26 4
gpt4 key购买 nike

我们的组织使用包含我们组织的 StyleCop.Analyzers 设置的规则集文件。这存在于源代码控制中,我们组织中所有解决方案中的所有项目都引用此文件。如果我编辑规则集(通过项目属性 -> 代码分析选项卡),我会看到一条消息,提示我将规则集迁移到 editorconfig 文件。有人可以解释为什么我想要这样做,两者之间有什么区别?
我还注意到在 VS 工具->选项->文本编辑器->C#->代码样式中,有许多设置与许多 StyleCop.Analyzers 规则非常相似(例如,与使用“this ", vs StyleCop SA1101 "用这个前缀本地调用")。这里还有一个按钮可以根据这些设置创建 editorconfig 文件,那么这些设置如何与 StyleCop.Analyzer 设置共存,哪个优先?
此外,我们的 Azure DevOps 自动生成报告警告,其中任何代码“违反”了 StyleCop 规则。如果我们用 editorconfig 文件替换规则集,构建是否仍会执行此操作?
最后,有一个用于编辑 StyleCop.Analyzer 设置的 GUI(项目属性 -> 代码分析选项卡 ->“配置”按钮),而 editorconfig 文件似乎是使用 VS 文本编辑器编辑的。鉴于有数百条规则需要管理,您从哪里获得需要输入的完整规则列表?这会不会很乏味?

最佳答案

报价和图片来自https://docs.microsoft.com/de-de/visualstudio/code-quality/use-roslYn-analyzers?view=vs-2019#rule-severity

Setting a rule's severity in an EditorConfig file takes precedenceover any severity that's set in a rule set or in Solution Explorer.


Visual Studio 中的设置(VS Tools->Options->Text Editor->C#->Code Style)在没有给出 .editorconfig 文件或没有在其中配置规则时使用。
根据我的经验,最好只选择一种配置方式。我还经历过,.editorconfig 文件的以下描述配置不起作用/或编辑 .ruleset 只要任何 .ruleset 文件可用。
通过灯泡配置规则
Configure rule via light bulb
通过错误窗口配置规则
Configure rule via error window
通过解决方案资源管理器配置规则。这也是您可以找到所有可用规则列表的地方。
Configure rule via Solution Explorer
命令行工具尊重 .editorconfig 文件:

When you build your project at the command line, rule violationsappear in the build output if the following conditions are met:

  • The analyzers are installed as a NuGet package and not as a VSIX extension.
  • One or more rules are violated in the project's code.
  • The severity of a violated rule is set to either warning, in which case violations on't cause build to fail, or error, in which case violations cause build to fail.

关于visual-studio - 对规则集文件与 editorconfig 文件感到困惑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63245342/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com