VS2010 / Code Analysis: Turn off a rule for a project without custom ruleset

南楼画角 提交于 2020-01-14 05:11:47

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2666043/vs2010-code-analysis-turn-off-a-rule-for-a-project-without-custom-ruleset

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!