Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Map dependencies across your solutions

When you want to understand dependencies across your code, visualize them by creating code maps. This helps you see how the code fits together without reading through files and lines of code.

Graph with selected items and expanded groups

Here are some videos:

To use code maps you’ll need either:

  • Visual Studio Enterprise: Create code maps from the code editor, Solution Explorer, Class View, or Object Browser.

  • Visual Studio Professional: Open code maps, make limited edits, and navigate code.

Caution note Caution

Before you share maps created in Visual Studio Enterprise with others who use Visual Studio Professional, make sure that all the items on the map (such as hidden items, expanded groups, and cross-group links) are made visible.

You can map dependencies for code in these languages:

  • Visual C# .NET or Visual Basic .NET in a solution or assemblies (.dll or .exe)

  • Native or managed C or C++ code in Visual C++ projects, header files (.h or #include), or binaries

  • X++ projects and assemblies made from .NET modules for Microsoft Dynamics AX

To see the overall dependencies across your solution

  1. Open the Architecture menu.

  2. If you just opened the solution and haven’t yet built it, or if your code has changed since the last time you built it, click Generate Code Map for Solution.

  3. If your code hasn't changed since the last time you built it, click Generate Code Map for Solution Without Building to get faster performance when creating the map.

  4. See overall dependencies to understand how you can use code maps to view the overall dependencies across your solution.

To see specific dependencies within your solution

  1. With your solution loaded, open Solution Explorer.

  2. Select all the projects, assembly references, folders, files, types, or members that you want to map.

  3. On the Solution Explorer toolbar, click Show on Code Map. You can also drag items from Class View or Object Browser into a new or an existing code map.

  4. See specific dependencies to understand how you can use code maps to view specific dependencies within your solution.

To add a new empty code map to your solution

  1. In Solution Explorer, open the shortcut menu for your top-level solution node. Click Add then click New Item.

  2. Under Installed, click General.

  3. In the right pane, click Directed Graph Document.

    You now have a blank map, which appears in your solution's Solution Items folder.

To create a new empty code map without adding it to your solution

  1. Open the Architecture menu and click New Code Map.

    - or -

  2. Open the File menu and click New then click File.

  3. Under Installed, click General.

  4. In the right pane, click Directed Graph Document.

    You now have a blank map, which does not appear in your solution's folders.

You can also:

  1. On the Architecture menu, click Generate Code Map for Solution.

    You get a map that shows the top-level assemblies and aggregated links between them. The wider the aggregate link, the more dependencies it represents. The Externals group contains anything outside your solution, including platform dependencies. External assemblies show only those items that are used. By default, system base types are hidden on the map to reduce clutter.

    Top-level dependency graph of assemblies

  2. Use the Legend button on the code map toolbar to show or hide the list of project type icons (such as Test, Web, and Phone Project), code items (such as Classes, Methods, and Properties), and relation types (such as Inherits From, Implements, and Calls).

    Use the Legend button to show the project icons

  3. To see inside an assembly, expand it. Move your mouse pointer on top of an assembly, and then click the chevron (down arrow) when it appears. Or use the keyboard by selecting the item then pressing the plus key (+). To explore deeper levels of code, do the same for namespaces, types, and members.

    Dependency graph with grouped nodes

    By default, containment relationships appear as groups, which you can expand and collapse.

    Dependency graph with nodes and links

  4. To simplify the map and focus on individual parts, click Filter on the code map toolbar and select just the types of nodes and links you are interested in. For example, hide all the test projects and assemblies by clearing the Test Asset checkbox.

    Use the Filter pane to simplify the display

  5. To examine items and dependencies represented by an aggregate link, first select the link and then open its shortcut menu. Click Show Contributing Links on New Code Map, or click Advanced and then Show Contributing Links. Visual Studio expands the groups at both ends of the link and shows only those items and dependencies that participate in the link.

  6. To get more information about an item or link, move the pointer on top of the item until a tooltip appears. This shows the categories that a link represents. To see what the link color means, on the map toolbar, click Legend.

    Tip Tip

    If you see a green link, it might not mean there's just an inheritance relationship. There might also be method calls, but these are hidden by the inheritance relationship. To see specific types of links, use the checkboxes in the Filters pane to hide the types of nodes you aren’t interested in.

  7. To see dependencies between members across groups, click an item on the map.

    Graph with selected items and expanded groups

  8. To find potential problems in your code, run an analyzer.

See:

  1. Create an empty code map, or open an existing code map (.dgml file).

  2. Drag the assemblies or binaries you want to map from outside Visual Studio onto the map.

Note Note

You can drag assemblies or binaries from Windows Explorer or File Explorer only if you are running it and Visual Studio at the same User Access Control (UAC) permissions level. For example, if UAC is turned on and you are running Visual Studio as Administrator, Windows Explorer or File Explorer will block the dragging operation. To work around this, make sure that both are running with the same permission level, or turn UAC off.

For example, suppose you have a code review to perform in some files with pending changes. To see the dependencies in those changes, create a code map from those files.

Dependency graph with grouped nodes

  1. Open Solution Explorer. Select the projects, assembly references, folders, files, types, and members that interest you.

  2. Map your items and their members. On the Solution Explorer toolbar and click Show on Code Map Create New Graph From Selected Nodes Button.

    To find items that have dependencies on types or members, open the type or member's shortcut menu from Solution Explorer. Click the dependency type. Then select the results.

    You can also drag items to a blank or existing map. To create a blank map, see Create an empty code map. To include the parent hierarchy for your items, press and hold the CTRL key while you drag items, or use the Include Parents button on the code map toolbar to specify the default action. You can also drag items from Class View or Object Browser.

    Note Note

    When you add items from a project that's shared across multiple apps, like Windows Phone or Windows Store, those items appear on the map with the currently active app project. If you change context to another app project and add more items from the shared project, those items now appear with the newly active app project. Operations that you perform with an item on the map apply only to those items that share the same context.

  3. To explore items, expand them. Move the mouse pointer on top of an item, then click the chevron (down arrow) icon when it appears. To expand all items, select them using CTRL and A, then open the shortcut menu for the map. Click Advanced, Group, Expand or Expand All.

    Note Note

    These options aren't available if expanding all groups creates an unusable map or memory issues.

  4. To focus on specific items in the map or to simplify the current view, select one or more items, open the shortcut menu for the map, and click New Graph from Selection.

  5. To see members that are in the code but don't appear on the map, click Refetch Children Refetch Children Icon. These group members appear with a different style so you can see them more easily.

  6. To see more items related to those on the map, select one and click Show Related on the code map toolbar, then select the type of related items to add to the map. Alternatively, select one or more items, open the shortcut menu, then:

    For an assembly, click:

    Show Assemblies This References

    Add assemblies that this assembly references. External assemblies appear in the Externals group.

    Show Assemblies Referencing This

    Add assemblies in the solution that reference this assembly.

    For a namespace, click Show Containing Assembly, if it's not visible.

    For a class, click:

    Show Containing Namespace

    Add the parent namespace.

    Show Base Types

    For a class, add the base class and the implemented interfaces.

    For an interface, add the base interfaces.

    Show Derived Types

    For a class, add the derived classes.

    For an interface, add the derived interfaces and the implementing classes or structs.

    Show Types This References

    Add all classes and their members that this class uses.

    Show Types Referencing This

    Add all classes and their members that use this class.

    Advanced | Show Containing Namespace and Assembly

    Add the parent container hierarchy.

    Advanced | Show All Base Types

    Add the base class or interface hierarchy recursively.

    Advanced | Show All Derived Types

    For a class, add all the derived classes recursively.

    For an interface, add all the derived interfaces and implementing classes or structs recursively.

    For a method, click:

    Show Containing Type

    Add the parent type.

    Show Methods This Calls

    Add methods that this method calls.

    Show Fields This References

    Add fields that this method references.

    Advanced | Show Containing Type, Namespace, and Assembly

    Add the parent container hierarchy.

    Advanced | Show Overridden Methods

    For a method that overrides other methods or implements an interface's method, add all the abstract or virtual methods in base classes that are overridden and, if any, the interface's method that is implemented.

    For a field, click:

    Show Containing Type

    Add the parent type.

    Advanced | Show Containing Type, Namespace, and Assembly

    Add the parent container hierarchy.

  7. To simplify the map and focus on individual parts, click Filter on the code map toolbar and select just the types of nodes and links you are interested in. For example, turn off display of test assets.

    Use the Filter pane to simplify the display

If you want to create more complete maps for C++ projects, set the browse information compiler option (/FR) on those projects. See /FR, /Fr (Create .Sbr File). Otherwise, a message appears and prompts you to set this option. If you select OK, this sets the option for just the current map. You can choose to hide the message for all later maps. If you hide this message, you can make it appear again. Set the following registry key to 0 or delete the key:

HKEY_CURRENT_USER\Software\Microsoft\VisualStudio\14.0\NativeProvider : AutoEnableSbr

When you open a solution that contains Visual C++ projects, it might take some time to update the IntelliSense database. During this time, you might not be able to create code maps for header (.h or #include) files until the IntelliSense database finishes updating. You can monitor the update progress in the Visual Studio status bar. To resolve issues or messages that appear because certain IntelliSense settings are disabled, see Troubleshoot maps for C and C++ code.

  • To see dependencies between all source files and header files in your solution, on the Architecture menu, click Generate Graph of Include Files.

    Dependency graph for native code

  • To see dependencies between the currently open file and related source files and header files, open either the source file or the header file. Open the file shortcut menu anywhere inside the file. Click Generate Graph of Include Files.

    First-level dependency graph for .h file

These items aren't supported for C and C++ code:

  • Base types don't appear on maps that include the parent hierarchy.

  • Most Show menu items aren't available for C and C++ code.

These issues might happen when you create code maps for C and C++ code:

Issue

Possible cause

Resolution

The code map failed to generate.

No projects in the solution were built successfully.

Fix the build errors that occurred and then regenerate the map.

Visual Studio becomes unresponsive when you try to generate a code map from the Architecture menu.

The program database (.pdb) file might be corrupted.

A .pdb file stores debugging information, such as type, method, and source file information.

Rebuild the solution and then try again.

Certain settings for the IntelliSense browsing database are disabled.

Certain IntelliSense settings might be disabled in the Visual Studio Options dialog box.

Turn on the settings to enable them.

See Options, Text Editor, C/C++, Advanced.

The message Unknown Methods appears on a method node.

This issue occurs because the name of the method cannot be resolved.

The binary file might not have a base relocation table.

Turn on the /FIXED:NO option in the linker.

See /FIXED (Fixed Base Address).

The program database (.pdb) file might not be built.

A .pdb file stores debugging information, such as type, method, and source file information.

Turn on the /DEBUG option in the linker.

See /DEBUG (Generate Debug Info).

Cannot open or find the .pdb file in the expected locations.

Make sure that the .pdb file exists in the expected locations.

Debug information has been stripped from the .pdb file.

If the /PDBSTRIPPED option was used in the linker, include the complete .pdb file instead.

See /PDBSTRIPPED (Strip Private Symbols).

The caller is not a function and is either a thunk in the binary file or a pointer in the data section.

When the caller is a thunk, try using _declspec(dllimport) to avoid the thunk.

See:

When you generate a map for the first time, Visual Studio indexes all the dependencies that it finds. This process might take some time, especially for large solutions, but this will improve later performance. If your code changes, Visual Studio re-indexes just the updated code. To minimize the time taken for the map to finish rendering, consider the following:

  • Map only the dependencies that interest you.

  • Before you generate the map for an entire solution, reduce the solution scope.

  • Turn off automatic build for the solution with the Skip Build button on the code map toolbar.

  • Turn off automatic adding of parent items with the Include Parents button on the code map toolbar.

  • Edit the code map file directly to remove nodes and links you don't need. Changing the map doesn't affect the underlying code. See Customize code maps by editing the DGML files.

Although Visual Studio can run with 1 GB of memory, we recommended that your computer have at least 2 GB of memory to avoid long delays while Visual Studio creates the code index and generates the map.

It might take more time to create maps or add items to a map from Solution Explorer when a project item's Copy to Output Directory property is set to Copy Always. This might cause issues with incremental builds and Visual Studio to rebuild the project each time. To increase performance, change this property to Copy if newer or PreserveNewest. See Incremental Builds.

The completed map will show dependencies only for successfully-built code. If build errors occur for certain components, these errors appear on the map. Make sure that a component actually builds and has dependencies on it before you make architectural decisions based on the map.

  • Use the File menu to save the map.

    -or-

    To save the map as part of specific project, on the map toolbar, click Share, Move <CodeMapName>.dgml into, and then choose the project where you want to save the map.

    Visual Studio saves the map as a .dgml file that you can share with other users of Visual Studio Enterprise and Visual Studio Professional.

    Note Note

    Before you share a map with those who use Visual Studio Professional, make sure to expand any groups, show hidden nodes and cross-group links, and retrieve any deleted nodes that you want others to see on your map. Otherwise, other users won't be able to see these items.

    The following error might occur when you save a map that is in a modeling project or was copied from a modeling project to another location:

    "Cannot save fileName outside the project directory. Linked items are not supported."

    Visual Studio shows the error, but creates the saved version anyway. To avoid the error, create the map outside the modeling project. You can then save it to the location that you want. Just copying the file to another location in the solution, and then trying to save it will not work.

  1. On the code map toolbar, click Share, Email as Image or Copy Image.

  2. Paste the image into another application.

  1. On the code map toolbar, click Share, Email As Portable XPS or Save As Portable XPS.

  2. Browse to where you want to save the file.

  3. Name the code map. Make sure that the Save as type box is set to XPS files (*.xps). Click Save.

Show:
© 2015 Microsoft