Recently I was exercising some of the OData APIs for manipulating a Windows Azure Access Control Service (ACS) namespace. I found some nice sample code, but the sample code was super-extensive (even including a Windows Phone sample), but my needs were humble (I wanted to manipulate ACS Reply-To addresses). After cutting out a few of the obvious projects so I could find “the code that mattered” I was still left with a heap of projects and libraries to weed out to get to the essential code – and it was tedious and error-prone to manually do this (if I was too aggressive, I broke the solution so it would no longer build). Frustration! How could I efficiently zoom in on the code I cared about so I could ensure I understood its requirements and dependencies?
This was two easy steps:
1. Create a simple program to exercise the code I cared about. This was a Console app I called TestRealmLib.exe.
2. Figure out everything that TestRealmLib.exe really depended upon.
Step one was easy since I knew the functionality I wanted to exercise.
Step two was easy once it dawned on me to use the right tool for the job: Visual Studio Ultimate 2012’s Generate Dependency Graph tool found under the ARCHITECTURE menu option.
NOTE: My understanding is that this feature is only fully available with Visual Studio Ultimate 2012, partially available in Premium (view but not create), and not available in lower editions – compare what’s included in which Visual Studio editions here: http://www.microsoft.com/visualstudio/eng/products/compare. I only have personally used it with Visual Studio Ultimate 2012 on solutions with C# projects (though I understand C++ is also supported, and assume any .NET language would work as well).
Running this for the whole solution, and rearranging the nodes with my mouse, quickly let me see where all the dependencies were.
I was quickly able to see that the modules I dragged to the right-hand side of the graph were not necessary, and those few on the left were the key. That was the answer I needed, but there are other interesting features. For example…
The thicker dependency lines represent more dependencies than the thinner lines. To drill in, right-click on a dependency line. Here’s what you get when you choose Advanced > Show Contributing Links on New Code Map:
Also note the “red dot” in the Code Map – this is indicating that I currently have a breakpoint set in there – yes, this is debugger-aware.
There are a bunch of other nifty features with this that you can check out here. These include dependency analysis, “Show Contributing Links” (on the dependency link to show which parts of module you are calling), and more. The UI gestures you’d expect all do something reasonable – like double-click, right-click, whether on nodes or lines. You can double-click a class or method name to jump to your C# code. And don’t forget to turn on the Legend (from toolbar at top of graph, not shown in my screen grabs) and explore the other features.
There is also a nice video demonstration in Channel 9: http://channel9.msdn.com/Series/Visual-Studio-2012-Premium-and-Ultimate-Overview/Visual-Studio-Ultimate-2012-Understand-your-code-dependencies-through-visualization