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:


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


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":


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


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:


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


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


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


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.


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.

Up Next
    Ebook Download
    View all
    View all