Favorite VS2010 Features: Dependency Graphs and DGML

As we get closer to the launch of VS2010 I’m covering some of my favorite new feature areas for VS2010.  For this post I’m going to talk about Dependency Graphs and it’s underlying support, DGML.

Generating Graphs

At some point I’m sure you’ve joined a team (or inherited a code base) which you did not create.  I’m guessing there is a good chance you didn’t wind up getting a fantastic set of documentation or architecture for some of those projects.  Wouldn’t you love to start by understanding what you’ve just gotten yourself into?  This is where Dependency Graphs come in.

Generating a dependency graph with VS2010 Ultimate is easy using the Architecture, Generate Dependency Graph menu:

image

In this case we’ll look at the diagram by namespace using the Tailspin sample application.  VS will walk through the binaries of the program looking for all of the dependencies and generate a DGML file with the data.  The top level view will start off with the namespace dependencies at the highest level (assembly boundary):

image

From  here you can navigate dependencies and drill down to more detailed information.  Simply hovering over an item will give detailed information about that item.  Hovering over a link will also provide additional information about the type of link (such as a method call or reference).  Clicking the expand button will update the graph to show the next level of detail:

image

You can continue to explore links and items to an increasing level of granularity.  In this example the classes in a namespace are shown:

image

You can continue to drill down all the way to the source code itself.

Architectural Explorer

Now that we have our visual view of the system, we can also use the Architectural Explorer to spelunk through our application.  Activating the explorer is easy:

image

The explorer window allows you to drill down on the contents by clicking as well as with filtering.  In this case we’ll find any class with ‘Model’ in the name and further drill down to the definitions in the class:

image 

This support is customizable and allows you to author queries you can re-run later.

DGML

Dependency Graphs are stored in XML using the DGML DOM.  Using DGML is very easy (Cameron has a getting started post here).  If you open the example above, you’ll find all the raw data for the Tailspin application:

image

This makes the system incredibly powerful because the DGML viewer in Visual Studio can be used to view any DGML document, including content you produce from your own tools.  As an example, VS ships with a built-in help file that explains how to use the mouse to interact with the DGML viewer.  That file itself is a DGML file:

image

There are many easy extensibility points with the system.  As an example we’ve had 3rd parties augment the dependency graph information to include more data such as runtime profiling coverage. 

Summary

This is just a few examples of the new ways to explore your existing software.  In addition to helping you understand the system, we want to provide tools that allow you to evolve the architecture (or fix as necessary).  That support includes being able to describe the logical tiers of your application and enforcement of layering with new changes.

To learn more, check out these great links: