15

Possible Duplicate:
What static analysis tools are available for C#?

Guys, I'm looking for an 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 anyone know of any such tool?

Mo Sadeghipour
  • 489
  • 8
  • 25
  • See the answers here: http://stackoverflow.com/questions/38635/what-static-analysis-tools-are-available-for-c Some static analysis tools can do deadlock detection. Also, try [FxCop](http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=917023f6-d5b7-41bb-bbc0-411a7d66cf3c) from Microsoft. – David d C e Freitas Jul 15 '11 at 10:53

9 Answers9

7

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.
  • 7,206
  • 3
  • 30
  • 52
6

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: Calculate code metrics, and you'll find an entire series of good suggestions there.

Community
  • 1
  • 1
Jeremy Frey
  • 2,334
  • 2
  • 22
  • 26
4

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
  • 1,224
  • 1
  • 15
  • 21
4

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

Igor Brejc
  • 18,714
  • 13
  • 76
  • 95
2

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

Reflector Add-Ins

I believe the CodeMetrics plugin does what you need

AlexCuse
  • 18,008
  • 5
  • 42
  • 51
  • I don't use VS 2008 at work, and CodeMetrics worked really fine for me. Thanks! –  Dec 24 '08 at 03:54
  • 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 Dec 24 '08 at 14:24
2

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

1

Visual Studio's Code Metrics

Alex
  • 12,749
  • 3
  • 31
  • 45
  • And the latest and greatest is [here](http://www.microsoft.com/downloads/en/details.aspx?FamilyID=edd1dfb0-b9fe-4e90-b6a6-5ed6f6f6e615) – Peter K. May 18 '11 at 20:45
  • 2
    both links are dead! – peval27 May 03 '17 at 10:36
  • [Here's the documentation](https://learn.microsoft.com/en-us/visualstudio/code-quality/code-metrics-values?view=vs-2022) for Visual Studio 2022 code metrics – Naktis Oct 25 '22 at 22:01
1

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
  • 2,115
  • 19
  • 21
1

I wrote a (completely) free code analysis app for .Net - Nitriq

viggity
  • 15,039
  • 7
  • 88
  • 96