Global.asax 中 Application_Start 的 StyleCop SP0100 错误
Style cop 会尝试强制您从 mvc Web 应用程序的 Global.asax 文件中的 Application_Start 中去掉下划线:
SP0100:方法(通用)名称 Application_Start 不符合 指定样式:SampleName。
但是这个名称不能在不破坏网络应用程序的情况下更改(我认为?)。
我在编写抑制消息来绕过此规则时遇到问题,并且由于某种原因,stylecop 中的分析器没有找到此错误[编辑 - 未找到错误,因为它是 StyleCop+ error] - 所以我无法自动生成模块级抑制消息。
有人可以帮助使用正确的抑制消息来克服这个问题吗?
我尝试过以下内容:
[module: SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Scope="member", Target="Global.asax", Justification = "Some justification")]
但没有运气
Style cop will try to force you to take the underscore out of Application_Start in the Global.asax file in an mvc web application:
SP0100: Method (general) name Application_Start doesn't conform the
specified style: SampleName.
But this name cannot be changed without breaking the web application (I think?).
I am having trouble writing the suppress message to bypass this rule, and also for some reason the analyzer in stylecop is not finding this error [Edit - the error is not being found because it is a StyleCop+ error] - so I am unable to auto-generate a module-level suppress message.
Can someone help with the right suppress message to use to get past this?
I have tried something along the lines of:
[module: SuppressMessage("StyleCopPlus.StyleCopPlusRules", "SP0100:AdvancedNamingRules", Scope="member", Target="Global.asax", Justification = "Some justification")]
But with no luck
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先,StyleCop 抑制确实很难记住,但最简单的方法是在你的方法之前或整个类之前使用它们。在您的情况下,抑制属性将如下所示:
其次,StyleCop+ 目前无法检测全局 ASAX 方法,因此它将它们视为常用方法并应用相应的规则。鉴于此,您可能可以对“方法(常规)”使用以下命名规则:
这里的缺点是方法 Application_DoWork 不会被违反,即使它与 Global ASAX 无关。
最后,您可以向 StyleCop+ 提交问题,以便它可以区分全局 ASAX 方法并对其应用单独的命名规则。
First, StyleCop suppressions are hard to remember indeed, but the easiest way is to use them just right before your method, or before the whole class. In your case suppression attribute will look like:
Second, StyleCop+ is not currently able to detect Global ASAX methods, so it considers them as common methods and apply corresponding rules. Given that, you could probably use the following naming rules for "Methods (general)":
The disadvantage here is that method Application_DoWork will not be violated, even it is not related to Global ASAX.
Finally, you could submit an issue to StyleCop+, so that it could distinguish Global ASAX methods and apply separate naming rules to them.