New ways to quickly create a Code Map

Code Maps, previously known as Directed Graph Documents, are a great way to visualize the relationships and interdependencies between the components of your applications. They make it much easier to understand the architecture of your (or, even more useful, somebody else’s) application, and where you should start when you need to update the application. Code Maps are a core part of the features of Visual Studio that help you to visualize and get insights about code.

clip_image002

OK, but I need more than one Code Map…

In Visual Studio 2013, you can create a Code Map by selecting Directed Graph Document in the New File dialog, from the Architecture menu, or by choosing Show on Code Map in Architecture Explorer, Solution Explorer, and the Debugger tool bar. However, it’s difficult to start a new and less cluttered Code Map to focus on specific components in an existing Code Map because Show on Code Map always adds code elements to the most recent Code Map. Meanwhile, the New File dialog and the Architecture menu just create a new blank Code Map without any styles.

In Visual Studio 2013 Update 3, we added the capability to drag arbitrary binaries from Windows File Explorer into a Code Map in order to understand their dependencies, and to try to componentize them. Of course, creating a new Directed Graph Document is a pre-requisite for this—which is also quite difficult to do. Many users found it hard to discover the options for creating a new Directed Graph Document, or became confused when prompted to create a new Modeling Project.

In Visual Studio 2015, both of these problems go away. We’re providing some new ways to create a Code Map that makes the feature easier to use, and—by removing unnecessary clutter—even more useful.

A day in the life of a developer …

Imagine that this is my first day with the team that produces Entity Framework (EF), and I’ve been given the simple task of adding a new command line option to the Migration tool. I’ve opened the EntityFramework solution, and generated a Dependency Graph using the option in the Architecture menu. This helps me to orient myself within the code, and I’m pleased to see that migrate.exe depends only on EntityFramework.dll. Immediately I know that I don’t have to examine the other projects.

clip_image004

Looking at the files in Solution Explorer I notice that the Migrate project contains a file named Program.cs. This will be my starting point, and so I select Show on Code Map to add it to the existing map.

clip_image006

I can see that Program has dependencies on Entity Framework.dll and on Externals, but the diagram is becoming more complicated and I still need to know more. So I expand Program to examine its contents, and the diagram now gets really cluttered. It contains many things that I’m not really interested in.

clip_image008

And every time I expand an item, the graph gets bigger and interaction with it becomes slower and more difficult. That’s not what I want. I want to keep the overview map (this helps me to stay oriented with the overall solution structure), but I also need to create a new Code Map. In Visual Studio 2013, I can try to find out how to do this using the Quick Launch box, but this doesn’t show anything useful.

clip_image009

Next, I try “DGML” because I noticed that this is the extension for the map files, but that shows nothing either. So I use the Add New Item option on the Projects menu, but entering “Code Maps” or “DGML” in the search box again finds nothing.

In the end I ask my colleague, who tells me that I need to create a new “Directed Graph Document” in the Add New Item dialog, or use the New Diagram option on the Architecture menu—and that forces me to create a Modeling Project that I don’t really want. It also gives me a new blank Code Map where I have to add the items I’m interested in.

The answer: new graph from selection!

In Visual Studio 2015, I can reduce the clutter without losing my existing high-level diagram of the solution structure or starting with a blank map by creating a new Code Map that contains only the selected items in the current Code Map. I simply select the components I’m interested in and choose New Graph from Selection in the short-cut menu.

clip_image011

Now I have a useful and uncluttered diagram focused on just the items I want to explore. I expand the migrate.exe item to see that it contains a Program item that depends on EntityFramework.dll.

clip_image012

I dive deeper by expanding the Program item to see its contents. It’s now clear that the object I need to work on is the CommandLine class.

clip_image013

Using Visual Studio Code Maps made it easy to get an initial overview of the solution and narrow down my exploration to locate the objects I need to work on, while feeling comfortable that I won’t miss anything. If I’d been doing this purely by examining the code itself, it would have been much harder to understand all the dependencies. With very little effort and intuition I’ve focused down on the CommandLine class, but I can continue generating more maps to help me both drill down and step back through the solution architecture.

And if I want a blank code map?

In addition, any time I do want a new blank Code Map, perhaps to examine a related object or assembly, I just choose the New Code Map option on the Architecture menu—without being forced to create a Modeling Project.

clip_image014

Got feedback?

Please try the improved Code Maps and send your feedback, ideas, and requests to vsarchfeedback@microsoft.com

Thank you,
The Code Insights team