Look at Dependency Graphs in Visual Studio 2012

In this article, we will look into dependency graphs, how to generate and analyze them in Visual Studio 2012. A dependency graph provides a visual way to examine code and its dependencies instead of going through each code file. This graph helps to understand complex or unfamiliar projects easily. Create a sample MVC 4 internet application or your existing project and go to the "Architecture" menu and click on "Generate Dependency Graph" as shown below:

Dependency-Graph-1.jpg

This will generate the following report with a .dgml extension that shows the dependencies of our solution:

Dependency-Graph-2.jpg

We can include additional items in the graph or code map by typing the item name in Solution Explorer and selecting "Show on Code Map":

Dependency-Graph-3.jpg

Selecting this option will include the item in Code Map and shows the following graph:

Dependency-Graph-4.jpg

We can use the above menu option to go to a definition or find references of it and so on.

We can even add extra items like methods, fields and so on to the Code Map by dragging and dropping it from the Architecture Explorer or from the Solution Explorer onto the designer as shown below:

Dependency-Graph-5.jpg

We can change the layout of the Code Map using the Layout option as shown below:

Dependency-Graph-6.jpg

We can run analyzers to find common issues like circular references, unreferenced items and so on from a Layout menu as shown below:

Dependency-Graph-7.jpg

We can even find callers and callees of a method/field by selecting the item in the designer and choosing the following options:

Dependency-Graph-8.jpg

We can add a comment as well to any item in the Code Map by clicking "New Comment" and "Save\share as Image" using the following options.

Dependency-Graph-9.jpg

We can use this Dependency Graph feature to understand code dependencies in a visual way as well as finding callers\callees, circular dependencies and so on in a complex and unfamiliar project quickly.


Similar Articles