tags:

views:

1927

answers:

8

Guys, I'm looking for a open source or free source code analysis tool for C#. The tool should be able to generate metrics from the source code such as cyclomatic complexity, number of lines, number of commented lines, SEI maintainability etc. Does any one know of any such tool? Thanks.

+1  A: 

There are many plugins for reflector (which is also free):

Reflector Add-Ins

I believe the CodeMetrics plugin does what you need

AlexCuse
I don't use VS 2008 at work, and CodeMetrics worked really fine for me. Thanks!
Glad it worked out. I'd echo everyone's sentiment that you should check out NDepend if you get a chance, it is great!
AlexCuse
+2  A: 

NDepend isn't free for non-academic or open-source software use, but it is awesome, and will give you those metrics (and many others, using its built-in Code Query Language).

This question is more or less a dupe of this one: http://stackoverflow.com/questions/60394/calculate-code-metrics, and you'll find an entire series of good suggestions there.

Jeremy Frey
NDepend does not work at source code level. but at intermediate language level.
jaircazarin-old-account
IIRC, last time I checked, NDepend works at the source code level for C#, but not VB.NET (IL only)
Jeremy Frey
+4  A: 

NDepend will give you a vast number of stats for your code:

http://codebetter.com/blogs/patricksmacchia/archive/2008/11/25/composing-code-metrics-values.aspx

There is a free 'Trial' version which contains fewer features than the Professional product, but which is free to use for Open Source and Academic development. The Trial version on the download page gets updated with a new version before the previous one runs out:

http://www.ndepend.com/NDependDownload.aspx

Dave R.
+2  A: 

Gendarme is totally open source and free. It's a subproject under mono. You can run the tools in three ways: wizard, console, NAnt. It will generate a html report which summarize all the violated rules. Worthy have a look.

Sun Liwen
A: 

Visual Studio's Code Metrics

Alex
+1  A: 

Most of these capabilities are included with Visual Studio 2008 Team System.

Under the Tools | Analyze menu there are options for Code Metrics. Most of your desired features are all there: Cyclomatic Complexity, LOC, and Microsoft's (a variant of the SEI maintainability index that instead goes from 0-100, where 100 is most maintainable) - as well as Depth of Inheritance, and Class Coupling as bonus features. It does not include number of commented lines.

codingoutloud
+1  A: 

Axivion Bauhaus Suite is free for academic use but not for commercial use.

It includes:

  • Software Architecture visualization
  • Software Architecture rule checking
  • Interface analysis
  • Cycle detection
  • Clone (copy) detection
  • Dead code detection
  • Detection of code style violations
  • A full set of predefined software metrics
  • The ability to add your own metrics and analyses...

Supports C / C++, C#, Java on various platforms

Mark Dalgarno
+1  A: 

SourceMonitor is a free C# metrics tool, it's fairly old but it could still be useful.

Igor Brejc