C# Visual Studio 代码分析与 StyleCop + FxCop
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/580168/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Visual Studio Code Analysis vs StyleCop + FxCop
提问by Jader Dias
I used previously StyleCop + FxCop on my Visual Studio's projects. But now I am testing Visual Studio Code Analysis tool, which is easier to integrate into MSBuild, and I have found that this tools analyses some of the rules of both FxCop and StyleCop.
我以前在 Visual Studio 的项目中使用过 StyleCop + FxCop。但是现在我正在测试Visual Studio Code分析工具,它更容易集成到MSBuild中,我发现这个工具分析了FxCop和StyleCop的一些规则。
Is this tool a full replacement for both FxCop and StyleCop or does it just implement some of their rules?
这个工具是 FxCop 和 StyleCop 的完全替代品还是只是实现了他们的一些规则?
采纳答案by Ben S
Visual Studio includes FxCop + more.
Visual Studio 包括 FxCop + 更多。
From the developer blog of FxCop:
Sorry about my ignorance, but I assume FxCop is completely separate from the Code Analysis in VSTS? More specifically, I assume that if I install the new version of FxCop, VSTS will not take advantage (no shared code?)? If this is the case, any idea when these changes will make it into VSTS code analysis? Thanks!
That's correct, they are different products, however they do have a common engine. Visual Studio 2008 SP1 already comes with the same fixes and analysis (plus a little bit more), so there is no need to 'update' Visual Studio with the latest FxCop.
抱歉我的无知,但我认为 FxCop 与 VSTS 中的代码分析完全分开?更具体地说,我假设如果我安装新版本的 FxCop,VSTS 不会利用(没有共享代码?)?如果是这种情况,您知道这些更改何时会进入 VSTS 代码分析吗?谢谢!
没错,它们是不同的产品,但它们确实有一个共同的引擎。Visual Studio 2008 SP1 已经附带了相同的修复和分析(加上一点点),因此无需使用最新的 FxCop“更新”Visual Studio。
A developer blogalso gave the exact rules which are in each.
一个开发者博客也给出了每个规则中的确切规则。
As for StyleCop, it's independent of VS Code Analysis as described in this blog post, which links to Jader Dias' post.
至于 StyleCop,它独立于 VS 代码分析,如本博文所述,该博文链接到Jader Dias 的博文。
回答by Jader Dias
Until now my googling resulted in the following answer:
到目前为止,我的谷歌搜索结果如下:
http://blogs.msdn.com/bharry/archive/2008/07/19/clearing-up-confusion.aspx
http://blogs.msdn.com/bharry/archive/2008/07/19/clearing-up-confusion.aspx
states:
状态:
"We found that StyleCop is, in fact, a very useful tool and it does things FxCop and TeamDev doesn't do (and it doesn't do the things they do). It is a wonderful complementary tool. StyleCop is a tool for doing coding style checking to verify that source code is formatted the way you want and follows the style guidelines for conventions. While there is some overlap with FxCop (like checking identifier capitalization), the overlap is miniscule as StyleCop does not do the deep analysis that the other static analysis tools do to enable code correctness checks, security checks, etc."
“事实上,我们发现 StyleCop 是一个非常有用的工具,它可以做 FxCop 和 TeamDev 不做的事情(而且它不做他们做的事情)。它是一个很好的补充工具。StyleCop 是一个工具进行编码风格检查以验证源代码是否按照您想要的方式格式化并遵循约定的样式指南。虽然与 FxCop 有一些重叠(如检查标识符大写),但重叠很小,因为 StyleCop 没有进行深入分析其他静态分析工具用于启用代码正确性检查、安全检查等。”
But I'm not sure if the "TeamDev" is the same thing as "Visual Studio's Code Analysis"
但我不确定“TeamDev”是否与“Visual Studio 的代码分析”相同
回答by Dylan Smith
My understanding is that Visual Studio Code Analysis is basically a slightly modified version of FxCop. From my experience they are almost the same thing (in fact I believe Code Analysis uses the FxCop executable behind the scenes).
我的理解是 Visual Studio Code Analysis 基本上是 FxCop 的一个稍微修改的版本。根据我的经验,它们几乎是一回事(事实上,我相信代码分析在幕后使用了 FxCop 可执行文件)。
Although there is overlap between FxCop/CodeAnalysis and StyleCop; FxCop tends to focus more on design rules and StyleCop is focusing on coding style (casing, white space, indents, etc).
尽管 FxCop/CodeAnalysis 和 StyleCop 之间存在重叠;FxCop 更侧重于设计规则,而 StyleCop 则侧重于编码风格(大小写、空格、缩进等)。
Also FxCop analyzes the IL while StyleCop analyzes the source code directly. This imposes a different set of restrictions on what rules they can each enforce.
FxCop 分析 IL,而 StyleCop 直接分析源代码。这对他们各自可以执行的规则施加了一组不同的限制。