English 中文(简体)
Stylecop vs FXcop
原标题:

Has Stylecop superseded FXcop? Which product should we be using with Visual Studio 2008?

最佳回答

Stylecop is a style analysis tool that works at the source code level. It exists primarily to provide a single common style that managed projects can use to remain consistent within the larger world of managed software. It makes decisions regarding style primarily to avoid holy wars (after all, style is almost always an inherently subjective thing). I don t think I ve ever met someone who liked all of StyleCop s rules, but that s ok. It means that StyleCop is a generally good compromise amongst the vast set of style guidelines that exist. (If stylecop s rules were highly customizable, beyond simply enabling/disabling them, it would defeat the entire purpose of the tool.)

FxCop, on the other hand, is a static analysis tool that works on the level of the managed assembly. It can be given directions via attributes because it can see attributes on code elements, e.g.. It detects problems that can be seen on the "binary" level (as it were) as opposed to the syntactic level.

To answer your question, StyleCop doesn t supercede FxCop, and FxCop doesn t supercede stylecop. They re two different tools with two different purposes that can both provide a real benefit for your code.

(AKA, I run with both. :) )


A couple examples of the things one might detect vs. things the other might detect:

StyleCop violations might include warnings related to: Whitespace, Formatting, Public method documentation via xml-comments, order of method definition within a class.

FxCop violations might include warning related to: Globalization, tight coupling, cyclomatic complexity, potential null dereferences.

问题回答

stylecop works on your C# source code. fxcop looks at your compiled code from any .net language.

An alternative or a good complement to FxCop/StyleCop would be to use the commercial tool NDepend. With this tool one can write Code Rule over LINQ Queries (namely CQLinq). Disclaimer: I am one of the developers of the tool

More than 200 code rules are proposed by default, these include design, architecture, code quality, code evolution, naming conventions, dead code, .NET Fx usage...

CQLinq is dedicated to write code rules that can be verified live in Visual Studio, or that can be verified during build process and reported in an HTML/javascript report.

The strength of CQLinq over FxCop or StyleCop, is that it is straightforward to write a code rule, and get immediately results. Facilities are proposed to browse matched code elements. Concretely this looks like that:

CQLinq code rule

FXCop does static code analysis of your managed code assemblies. Think of it as finding issues that will cause problems at run-time or that will affect how the developer believes the code will run (unreachable code).

StyleCop analyzes the structure of you code from a text point of view. Think of this as issues that will affect your development and design experience (Formatting, naming conventions, documentation)

They are both VERY valuable tools and you should use both but they do focus on different problems.

StyleCop performs source code analysis is not very configurable. It doesn t really do the same thing as FxCop, which analyzes the compiled code.

The wikipedia articles on these provide good summaries of the differences:

http://en.wikipedia.org/wiki/StyleCop

http://en.wikipedia.org/wiki/FxCop





相关问题
What features you like of FxCop?

I love ReSharper, but FxCop is free and does some bits ReSharper does. What can I do to get the best out of FxCop? I am using VS2008, and plan to upgrade to VS2010 next March hopefully.

Unit testing custom FxCop rules

I would like to test my custom fxrules. I ve seen this post : http://weblogs.asp.net/rosherove/archive/2007/02/24/writing-real-unit-tests-for-your-custom-fxcop-rules.aspx but it s not working with ...

Can t see my custom rules with fxcop

I m trying to develop a custom rule for fxcop. I ve this code : namespace TestCustomRuleFxCop { public class DoTheRightThingRule : BaseIntrospectionRule { public DoTheRightThingRule(...

FxCop command line and paths with spaces

I m having problems getting the FxCop command line to work when I specify paths with spaces in them. Yes, I use the quotes properly. M:uildIOServicesrc>"c:Program FilesMicrosoft FxCop 1.36...

热门标签