FxCop 或 StyleCop 中的自定义静态代码分析规则?
如果编写我自己的静态代码分析规则(针对 C# 代码),使用 StyleCop 与 FxCop 的优缺点是什么?
一种比另一种更适合某种类型的分析吗?或者两者之间的区别是一个在源代码上运行,另一个在编译后的程序集上运行?
If writing my own static code analysis rules (for C# code), what are the pros and cons of using StyleCop vs FxCop?
Is one more appropriate for certain type of analysis than the other? Or is the difference between the two that one runs on the source code and the other on the compiled assembly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
一个关键的区别是 StyleCop 分析 C# 源代码。 FxCop 在编译 .NET 程序集后对其进行分析,它适用于任何语言。因此,StyleCop 对源代码的外观很挑剔。 FxCop 对如何使用 .NET 框架类很挑剔。他们相辅相成。
A key difference is that StyleCop analyzes C# source code. FxCop analyzes .NET assemblies after they are compiled, it works for any language. Accordingly, StyleCop is picky about how your source code looks. FxCop is picky about how you use the .NET framework classes. They complement each other.
它们是不同的工具。 StyleCop 专注于代码风格。您可以检查文档。尽管 FxCop 可以做与 StyleCop 几乎相同的事情,但 FxCop 专注于 微软设计指南。它将分析您的代码,寻找可能的性能和安全问题等。
我从未为它们中的任何一个编写过规则,但我相信您应该选择能够完全满足您需求的规则(如果只是编码标准,请使用 StyleCop,否则,请使用 FxCop)。这样,您可能会对 API 感到更舒服。
检查这些维基百科链接:
They are different tools. StyleCop is focused on code style. You can check doc. comments, naming convention, spacing, etc. Altough it can do almost the same things as StyleCop, FxCop is focused on the Microsoft Design Guidelines. It will analyze your code looking for possible performance and security issues, among other things.
I never wrote rules for any of them, but I believe that you should go for the one that does exactly what you want (if just coding standards, go with StyleCop, otherwise, go with FxCop). This way, you'll probably feel more confortable with the API.
Check these Wikipedia links: