Jamie's Space

JP

Dependency Viewer

A while back I posted a quick app I wrote to display dependencies between visual studio projects using GraphViz (here). I’ve done a bit more work on it since then, cleaning up the project and adding support for custom processing of the graph elements before they are rendered using extensions. I’ve also put the project on GitHub for ease of updating. You can access that here: http://github.com/jamiepenney/VS-Dependency-Viewer

I’m going to talk about how the extension mechanism works. It uses the Managed Extension Framework (MEF), which you can read about here: http://www.codeplex.com/MEF. You don’t need to know a lot about MEF to write an extension - in fact you can get away without knowing anything apart from how to download it and which attribute to use on your extension class.

To create a custom graph processor, you’ll need to create a new Class Library project in Visual Studio. This project needs to reference Quickgraph.Graphviz.dll, System.ComponentModel.Composition, and DependencyViewer.Common.dll. The first two you can get from the lib directory in the Dependency Viewer project, and the Common dll you can get by building the DependencyViewer.Common project. Once you’ve got your project up and running, create a new class that implements DependencyViewer.Common.Interfaces.IGraphProcessor.

The IGraphProcessor interface is pretty basic so far. These are the important methods:

  • PreProcessGraph

    • This method lets you change formatting options on the graph before the other graph elements are processed. You could use this to set the size, background colour, etc.
  • ProcessEdge

    • This method lets you change formatting options on a dependency connection after the defaults have been set (there aren’t any defaults yet though).
  • ProcessVertex

    • This method lets you change formatting options on a project node after the defaults have been set. By default the Name is set to the name of the project and the shape is set to Ellipse.

You can have blank implementations of any methods you don’t need.

To get the main application to find your custom graph processor, you just have to register it as an implementation of IGraphProcessor by adding the Export attribute to your implementation. So in this case, you’d put [Export(typeof(IGraphProcessor))] on your class.

Once you’ve done that, build your project, copy the dll into the directory where you are running the main application, and then the magic happens. MEF will automatically pick up your implementation when you next render your solution.

There is an example implementation in the Dependency Viewer project called TestProjectProcessor. It finds non unit testing projects that reference NHibernate and colours them a different colour, so that you can see what projects refer to your data projects. I got the idea from Melle Koning’s blog post on the subject here.