tags:

views:

37

answers:

2

All our developers are using VS2010 professional so code analysis is not available. I want them to use FxCop to analyze the code before checking in. I have gone through the rules and disabled a bunch of them and added couple of them. I want all the developers to use same set of rules since it will be the rules used in MSBuild. How do I distribute the rule set to be used in FxCop? What files need to be distributed and where is it supposed to go to?

A: 

When using stand-alone FxCop, you can create an FxCop project file (with extension .fxcop) which contains the list rules that are to be used in the analysis. (Typically, the file will also include the list of target assemblies, although this is optional.) This file may be checked into source control with your code in order to distribute it to the developers working on the shared code base.

Nicole Calinoiu
Is it possible to predefine the rules as in my case and then distribute it all the developers?
Nair
That's exactly what my previous answer explained how to do. Do you need more detailed help with some particular step(s)? If so, could you please indicate which?
Nicole Calinoiu
A: 

An alternative to FxCop custom rules would be to use NDepend and its Code Query language (CQL). CQL is dedicated to write code quality rules that can be verified live in Visual Studio, or that can be verified during build process and reported in a HTML report. Here are a few samples of CQL rules (designed to be highly customizable):

Code refactored recently should be 100% covered by test:

WARN IF Count > 0 IN SELECT METHODS WHERE CodeWasChanged AND PercentageCoverage < 100

Complex methods should be commented:

WARN IF Count > 0 IN SELECT METHODS WHERE CyclomaticComplexity > 15 AND PercentageComment < 10

I don’t want that my User Interface layer to depend directly on the DataBase layer:

WARN IF Count > 0 IN SELECT NAMESPACES WHERE IsDirectlyUsing "DataLayer" AND NameIs "UILayer"

Static fields should not be named m_XXX (Custom naming conventions):

WARN IF Count > 0 IN SELECT FIELDS WHERE NameLike "^m_" AND IsStatic

Methods out of MyAssembly and MyAssembly2 should not have more than 30 lines of code:

WARN IF Count > 0 IN SELECT METHODS OUT OF ASSEMBLIES "MyAssembly1", "MyAssembly2" WHERE NbLinesOfCode > 30

Public methods should not be removed to avoid API breaking changes:

WARN IF Count > 0 IN SELECT METHODS WHERE IsPublic AND IsInOlderBuild AND WasRemoved

Types tagged with the attribute MyNamespace.FullCoveredAttribute must be thoroughly covered by tests:

WARN IF Count > 0 IN SELECT TYPES WHERE HasAttribute "MyNamespace.FullCoveredAttribute" AND PercentageCoverage < 100

Patrick Smacchia - NDepend dev
Without doubt it is easy to do with NDepeDoes NDepends come with default industry rules like FxCop?
Nair
Yes, download NDepend trial and you'll see that NDepend comes with more than a hundred of default rules, and many trails queries to let the user define its custom rules or customize existing ones.
Patrick Smacchia - NDepend dev