VS2010 /代码分析:关闭没有自定义规则集的项目的规则

发布于 2024-08-29 17:34:01 字数 364 浏览 3 评论 0原文

……有什么改变吗?

场景是这样的:

  • 我们为我们公司制定了代码的外观标准。
  • 这将是 MS 现在的完整规则集。
  • 对于某些特定项目,我们可能希望关闭特定规则。仅仅是因为对于特定项目来说这是一个“已知的例外”。例子? CA1026 - 虽然在大多数情况下完全没问题,但有 1-2 个特定的库我们不想更改它们。
  • 我们还希望避免使用自定义规则集。 OTOH 在每次出现时都添加抑制属性,很快就会变得非常复杂。

有没有办法在没有自定义规则集的情况下关闭完整程序集的代码分析警告?出于维护原因,我们宁愿将其放在特定文件(GlobalSuppressions.cs)中,而不是放在规则集中,并且更明确;)

...any change?

The scenario is this:

  • For our company we develop a standard how code should look.
  • This will be the MS full rule set as it looks now.
  • For some specific projects we may want to turn off specific rules. Simply because for a specific project this is a "known exception". Example? CA1026 - while perfectly ok in most cases, there are 1-2 specific libraries we dont want to change those.
  • We also want to avoid having a custom rule set. OTOH putting in a suppress attribute on every occurance gets pretty convoluted pretty fast.

Any way to turn off a code analysis warning for a complete assembly without a custom rule set? We rather have that in a specific file (GlobalSuppressions.cs) than in a rule set for maintenance reasons, and to be more explicit ;)

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

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

发布评论

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

评论(2

初见 2024-09-05 17:34:01

无法创建程序集级排除来涵盖程序集中类型和/或成员违反该规则的所有情况。

您可能仍然可以在项目文件中使用 CodeAnalysisRules 元素,但这本质上与自定义规则集一样多,而且由于它未显示在项目属性 UI 中,因此更难以跟踪。

无论您希望使用哪种机制,您还应该考虑是要简单地排除现有违规行为还是要引入新的违规行为。如果是前者,您应该为现有违规添加 SuppressMessage 属性。如果是后者,您应该禁用程序集的规则。

顺便说一句,如果您没有意识到这一点,您可以在 VStudio 的违规列表中一次抑制多个违规。

There is no way to create an assembly-level exclusion that will cover all violations of that rule for types and/or members within the assembly.

You could probably still use the CodeAnalysisRules element in your project file, but this is essentially just as much work as a custom ruleset, and more difficult to track given that it's not shown in the project properties UI.

Regardless of the mechanism you would prefer to use, you should also consider whether you want to simply exclude existing violation or whether you want new violations to be introduced. If the former, you should add SuppressMessage attributes for the existing violations. If the latter, you should disable the rule for the assembly.

BTW, in case you weren't aware of this, you can suppress multiple violations at once in the violation list in VStudio.

过气美图社 2024-09-05 17:34:01

实际上,您可以使用 CodeIt.Right 进行静态排除,从而获得更大的灵活性分析。并节省了所有时间:)

You'd actually have more flexibility of exclusions with CodeIt.Right for static analysis. And saved all that time :)

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