tags:

views:

765

answers:

4

I have been using SourceMonitor on my project for a couple of years to keep records of source-code complexity and basic SLOC (including comments) for C# and C++ components. These are used for external reporting to our customer, so I'm not in a position to argue their merits or lack of.

I've been working on a repository analysis tool which is able to give me a snap-shot view of the project at any date/time. The next stage I want to add is caching of the metrics for a specified file and revision.

I know SourceMonitor can be scripted to allow me to supply the files to be tested and grab the metrics out of the result file CSV or XML.

Is there a native library in .NET that I could use to do the same thing -- e.g. avoid spawning an external process and parsing the results.

I only really need the following metrics:

  • SLOC
  • Number of comment lines
  • Complexity of most complex method
  • Name of most complex method

I need to run this on C# code and normal C++ code.

Edit: since I already have tool which provides the GUI and reports I want, the metrics need to be scripted or generated using a library/API without manual steps. Ideally I want to get metrics for a specified file/revision (rather than a whole project) which my utility will drag from version-control automatically.

NOTE: I created a bounty for this and was on holiday when it expired... the NDepends answer does NOT satisfy me as it doesn't look at source-code but the assembly itself!!!

+2  A: 

NDepend

Matt Howells
Does that have an API? Does it work on individual source-files or the whole project? Quite expensive for my needs and does lots I don't need, given I currently do this using SourceMonitor.
Ray Hayes
NDepend inspects assemblies, not source code. But it could produce very complete reports and has a lot of awesome features for getting and exploiting code metrics. I'm not aware of any NDepend API, thus.
Romain Verdier
I really need source code analysis.
Ray Hayes
A: 

This won't give you function complexity and it's not scriptable (that I know of), but the SlickEdit Gadgets for VS has a great SLOC report tool and you can use from the solution explorer and will give you a detailed report at the file, project or solution level.

You can get it here: http://www.slickedit.com/content/view/441

Adam Haile
+2  A: 

You can find an open source code for C# SLOC and comments here: http://code.google.com/p/projectpilot/source/browse/#svn/trunk/ProjectPilot.Framework/Metrics

Igor Brejc
A: 

Whilst I never did find a .NET product that can equally parse C# and C++, I did manage to find an easy-to-use product, CODECOUNT that supports those languages and many more.

It has a simple command line, unlike SourceMonitor that was being used on my project up until CODECOUNT replaced it.

Ray Hayes
But SourceMonitor does offer command line invocation.
reinierpost