views:

482

answers:

4

Hi,

I wanted to ask whether you know about some free C# libraries (dlls) that calculate CK metrics (mainly Cyclomatic Complexity).

I would need that for a project I'm planning to do. I know that there are already some finished solutions that calculate CK metrics and display it to you in various forms, but what I would need is one that I could use from within my application. So before starting and writing one myself I first wanted to ask you.

Thanks

+2  A: 

I am using SourceMonitor, which is a nice freeware app that measures code complexity and other metrics for a variety of languages including C#. We drive it from the command line to produce XML output, then we use LINQ to XML to extract and sort the data we are interested in. We then use NVelocity to create HTML reports.

I know its not a managed library, but you might find it can do what you need.

Mark Heath
thx for the info. But the problem is that my app is not just considered for personal use, but potentially for others and so it's a bit inconvenient if they have to install it in order to use my app. But I'll take it into consideration, thx
Juri
A: 

With 82 code metrics supported NDepend is the code metrics Roll's Royce tooling for .NET developers (however it is a commercial tool).

Patrick Smacchia - NDepend dev
+7  A: 

DrivenMetrics is a open source C# command line tool. The core functionalities are isolated from the command line console client as a library (Core project is available here).

Even if quite simple, it may fit your need: it's free, counts the the number of lines and calculates the cyclomatic complexity (number of potential code paths) of methods.

This is performed through direct analysis of the IL thanks to Mono.Cecil (the same library NDepend relies on). This allows the analysis to be performed on assemblies built from code written in C#, VB.Net,...

  • The project has been announced here.
  • The code source is available on github.
  • A packaged release is also available.
  • It works both on Windows and Mono.
Em.
Thanks! This looks really great! But where you able to run it? I checked out the core source, build it and then got 3 ddls. Then i referenced this 3 DDLs in my project. But then what to do? I can't see any documentation on this.
Roflcoptr
@Roflcoptr: Take a look at the Driven.Metrics.Tests.Core.Metrics.ILCyclomicComplexityTests class in the DrivenMetrics.Tests projects. This test class will show you how to load an assembly (in the Setup() method), how to select a method to analyze, and how to apply an ILCyclomicComplextityCalculator to it to calculate the CC of the method (see method ShouldDetermineCyclomicComplexityForFooSecond() for instance).
Em.
sorry i misformed my question i think :D i was wondering how I can use this. I included the file DrivenMetrics.dll in the references of my project. This should do the trikc right?
Roflcoptr
A: 

It isn't free but I've had good experiences with NCover for this sort of thing. They also integrate pretty well with a lot of CI tools out there.

Jeremy T