Understand Code Dependencies with Visual Studio

2014-10-11

Visual Studio provides a convenient tool to generate visual code dependencies. It helps to identity circular references issues and also hubs.

To learn more details about this function, visit http://msdn.microsoft.com/library/dd409453(VS.110).aspx.

Find the tool

Go to menu “Architecture –> Generate Dependency Graph” and you will be able to generate the visual diagrams for your projects or solution.

/project/tools/resources/391ADA15-580C-5BAA-B16F-EEB35D9B1122.webp

Sample – Hub

/project/tools/resources/B7D55BF4-7057-5113-85C8-141871BF7635.webp

ContextProject.DataServices.The above diagram shows how my projects reference to each other.  Three projects are Hubs: ContextProject.Website, ContextProject.DataServices.Syndication, ContextProject.DataServices.MetaWeblog and ContextProject.DataServices, which implies that they are the top 25% highly connected nodes.

/project/tools/resources/D6ED313E-533A-55A6-AA06-4C00BC132812.webp

Because of these dependencies, it is hard to change and maintain the code. We can refactor can components to reduce the complexity of dependencies.

Sample – Circular Reference

Expand the assembly nodes,  we can identify the circular references.

/project/tools/resources/751AF8B4-32A7-55BC-9FAD-8BFBCBBF4237.webp

In the above diagram, three namespaces form a circular reference. Drilling-down to details, I find out the static property Configurations caused this issue.

/project/tools/resources/A4C08562-50FA-5599-939C-EB6F2A83A362.webp

Sample – Other

I am planning to replace my IoC component NInject with Microsoft Unity. The visual dependency diagram can help me to find out all the classes/properties/methods I need to change.

/project/tools/resources/61C97311-BB14-5679-99FC-98497A701292.webp

Summary

The visual dependencies can help us identify code that might be overly complex or that might need improvement. It will be very useful when you begin to analyze a new project you didn’t work on before.