views:

105

answers:

4

Pretty straightforward question here: I like tools such as FxCop when it comes to scanning assemblies to get better insight into my code, and would like to start doing it on C# 4.0 assemblies. Any out there yet, or should I sit tight for a few more months while it's released and tools are updated?

+3  A: 

The VS2010 beta includes a newer version of Code Analysis, which runs FxCop during the build process and displays the output as warnings. See the Code Analysis tab of project properties.

However, it's only available in the Premium and Ultimate editions. (See comparison)

I really wish that Microsoft would include it in the Express Editions and enable it by default for all projects; that might substantially improve beginner code.

SLaks
Interesting! Though I downloaded VS2010 Pro last week (10.0.21006.1 B2Rel) and don't see it on a class-output project's properties. Maybe because I updated the project from a 2008 project? I'll dig into it.
Chris
I believe it's only available in Premium and Ultimate.
SLaks
+3  A: 

What about Microsoft StyleCop for Visual Studio 2010?

Rubens Farias
Bam! Nice, thank you.
Chris
A: 

The SD C# Clone Doctor statically analyzes C# (yes, even version 4.0) source code for duplication.

The CloneDR can be applied to large scale software systems, and typically finds 10-20% duplicated code.

There is a sample clone report at the link.

Ira Baxter
+1  A: 

You can 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