This article is about using Code Maps in Visual Studio 2012 to understand relationships in code. Code maps comes with Visual Studio Ultimate Update 1 and helps you to visualize code relationships to understand better. Visual aids help humans to understand in better way and code maps is a great tool to help to understand complex projects form visuals.

To create code maps, Visual Studio Ultimate 2012 update 1 or higher is required. However Premium or Professional version allows limited edits and navigation in code but still allows you to create code maps.

Overview

Maintaining an oversized code base is tough. Diving in and understanding an strange code base is even harder. however each developer has had to try to to this at some purpose in his career. There are multiple approaches you’ll be able to take, most of that typically find yourself with you employing a piece of paper to diagram out relationships in your code.

Visual Studio 2012 provides an architecture tool to assist with this: the dependency graph. With dependency graphs, you’ll be able to simply produce a visible illustration of a project or solution, that you’ll be able to drill into for details. Visual Studio 2012 Update one provides an excellent and lot easier tool for creating and manipulating this kind of mental image, referred to as a code map.

Similar to dependency graphs, code maps enable you to check code relationships. after you produce a brand new code map, it seems in a tab next to the code editor. this enables you to check wherever you’re within the hierarchy of the code while you are operating within the code itself.

Getting Started

To start using this amazing feature just open source code file from your solution in Visual Studio, navigate to a method name, right click and choose “Show on Code Map”. A new tab with title “CodeMap1.dgml” will appear next to the source code that containing only one node in it as shown in the figure below:





Have you noticed the green arrow next to the node? This green arrow tells that cursor is currently on this method. For an instance move cursor to a different method from source code file, and therefore the arrow next to your node will disappear. If you choose the method once more, green arrow reappears next to the node.

Double-clicking a node on the code map takes you on to that method. Not only this, it also highlights all the places where that particular method is called within that particular source code file (you will see this in above Figure). On hovering over the node in Code map, a pop-up window will appears that elaborate data regarding the node.

Finding all References

For an instance, you wish to find all the methods that calls a particular method. Just simply right-click on the method and choose “Find All References on Code Map”. You will see that all the methods that calls the particular method will appears in Code Map as shown in Figure below.





You can see that latest nodes added in code map diagram are highlighted in green, that makes it easier to track changes in code map. Code map is able to grow in self depending on number of nodes being added. You can change zoom of code map diagram from top bar of the tab. You can also change orientation of diagram using tools from top bar of tab

Assigning Color to Node

To distinguish certain nodes from other or to indicate needed actions to be taken on node, you can assign a unique color to the node. To change node color, simple right click on node and hit Flag for Follow Up to set node color to red or point to Select Other Flag Colors and select a different color for the node.

Adding Comments

Further comments can be added on the code map nodes to provide more information about node or context. Comments can added by right clicking on a particular node and hit New Comment. Comment can be made edited by double clicking on comment and press enter key to update the comment. Further you can drag comments to organize them in the Code Map. Below figure shows a comment added to the Method2 node.



Sharing Code Maps

You are not going to create code maps only for personal use. But you might also be interested in sharing code maps with other team members to help others in understanding relation in that particular code. Code maps can be shared in several ways. You can see a Share button on top bar of tab. Clicking this will gives you a all the options for sharing. You can either export Code Maps as XPS document or create an image file that you are going to share with other team members via e-mail. There are several other options too. You can create a DGML file in solution that allows other team members to further enhance the code map or organize nodes in their own way.