VS2010 /代码分析:为没有自定义规则集的项目关闭规则 [英] VS2010 / Code Analysis: Turn off a rule for a project without custom ruleset

查看:99
本文介绍了VS2010 /代码分析:为没有自定义规则集的项目关闭规则的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

...有任何变化吗?

...any change?

情况是这样的:


  • 对于我们公司,我们开发了一个标准的代码外观。

  • 这将是现在看起来的MS完整规则集。

  • 特定项目,我们可能要关闭特定规则。仅仅因为对于特定项目,这是已知异常。例? CA1026-尽管在大多数情况下还可以,但是我们不想更改1-2个特定的库。

  • 我们还希望避免使用自定义规则集。 OTOH在每种情况下都设置了抑制属性,很快就会非常费解。

  • 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.

任何一种关闭代码分析警告的方式没有自定义规则集的程序集?出于维护原因,我们宁愿将其保存在特定文件(GlobalSuppressions.cs)中,也不要将其保存在规则集中,并且更明确一些;)

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 ;)

推荐答案

无法创建一个程序集级别的排除项,以涵盖程序集中的类型和/或成员对该规则的所有违反。

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.

您可以可能仍会在项目文件中使用CodeAnalysisRules元素,但这实际上与自定义规则集的工作量相同,并且由于未在项目属性UI中显示,因此更难跟踪。

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.

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

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,如果您不知道这一点,则可以一次禁止多次违反在VStudio中列出。

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

这篇关于VS2010 /代码分析:为没有自定义规则集的项目关闭规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆