views:

271

answers:

4

We have a c# app that uses a number of libraries (that we wrote too). The app depends on the different libraries and some of the libraries depend on some of the other libraries.

Now when it comes to testing the app we also need to make sure that the libraries are all working correctly. The problem is that the app only uses a small amount of the functionality of these libs. I can use something like NCover to find which library classes are actually used but I would also love to know how these classes (across the app and different libs) are organised - their dependency structure.

So my question: I want to be able to run my app and then get the list of classes used, organised by dependencies (ie what calls/uses what).

Does anyone know of any tool (free or not) that allow you to do that? The code is all in VS2008 organised with the different libs/app as projects.

+2  A: 

I think you'll want to look at:

Reflector

from Red Gate software. It's free, and is probably the best and most well known disassembly/debugging tool for .NET. It has a plug-in architecture, too, and there is a Codeplex page, .NET Reflector AddIns that contains a number of very useful add-ins for it.

For looking at dependencies, I think the Graph plug-in should give you want you're after.

There is also a very similar (and also very good tool) on SourceForge called Refractor which will also show dependency graphs.

CraigTP
thanks! Reflector allows me to browse the dependencies just like I wanted - using the Depends On part of the Analyser. Graph doesn't really draw a picture of what I wanted. When I have more time I might look into making a plug-in. I Appreciate the help!
David Jacka
+2  A: 

NDepend analyzes dlls and shows a graph with dependencies between the classes, it's a great (but not free) code analysis tool. They have a trial edition that you can use for a few months so you can give it a go.

Gergely Orosz
Thanks for the suggestion.I had a look at NDepend and, although it gave me a whole bunch of interesting visualisations, it didn't actually answer my underlying question: If i want to test class X, what other classes do I need to test (and in what order). It partly may be due to the trial edition being a bit limited but I'm not going to buy something that _might_ work.
David Jacka
I beleive it indeed doesn't show you a graph of that. The trial is not limited, so that's clearly not the right tool for you, sorry about that!
Gergely Orosz
A: 

You can try the RC release of Visual Studio 2010 Ultimate to generate dependency graphs for .NET code. You can generate a graph of all your assemblies, namespaces, classes, or some combination of these, or you can use Architecture Explorer to select specific artifacts and the relationships that you want to visualize:

How to: Generate Graph Documents from Code: http://msdn.microsoft.com/en-us/library/dd409453%28VS.100%29.aspx#SeeSpecificSource

You can use Visual Studio Ultimate to explore the relationships and organization in existing code by generating directed graph documents. These graphs represent code elements and their relationships as a set of nodes that are connected by links, or edges. You can use these graphs to help you visualize, explore, and analyze code.

How to: Find Code Using Architecture Explorer: http://msdn.microsoft.com/en-us/library/dd409431%28VS.100%29.aspx

You can select vertical sections or "slices" of code that you want to visualize by using Architecture Explorer. You can explore source code in a Visual Studio solution or compiled managed code in .dll files or .exe files. You can use Architecture Explorer to browse other domains by installing additional providers. When you find the code that you want to visualize, you can generate graphs to explore the relationships in that code.

RC download: http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=457bab91-5eb2-4b36-b0f4-d6f34683c62a.

Visual Studio 2010 Architectural Discovery & Modeling Tools forum: http://social.msdn.microsoft.com/Forums/en-US/vsarch/threads

Esther Fan - MSFT
A: 

To complete the answer of Gergely on NDepend, NDepend comes with a dependency graph coupled with a dependency matrix. You can try NDepend straight on your code thanks to a Free Trial Edition.

See screenshoots extracted from this blog post: Interactive Code Dependencies Graph

For example see below the dependencies between the classes contained in System.Collections.Generics. To obtain such dependency, just right click the namespace or assembly, and click View internal dependencies on Graph (or on Matrix)

alt text

Other graph samples generated by NDepend:

alt text

alt text

alt text

Patrick Smacchia - NDepend dev