Visual Studio 11 has radically improved the Dependency Graph Features. To take it for a spin I’ve loaded a real project that I’m working on, it contains about 25000 lines of code. I can use the simplified top down dependency graph feature we see here under the Architecture menu and I see something new right off the bat called “Indexing the code”.
What’s happening here is that Visual Studio 11 (I’ll call it dev11 from now on) is building a SQL database of all the dependencies in my code which in this case takes about 34 seconds. Then it will use this database for all subsequent queries on the graph making the overall experience much better and it didn’t take much longer than dev10. On dev10 the same operation on this solution takes 30 seconds. So you’re paying a little overhead for the SQL database but you’ll see in a minute how much better the experience is as a result.
For example, you’ll see that this top level dependency graph is very small, it only contains 20 nodes and 49 links. The same top level graph in dev10 has about 12000 nodes and 60000 links, all hidden inside these collapsed groups, but that made any interaction on the canvas sluggish at best.
Dev11 instead is able to query the code index every time I expand something and get the detail. Let’s try that here. Oooh, nice smooth animation there too! It found 4 new nodes. You can see that there is an animation happening in the background here because it’s also fetching all the new dependencies for the nodes it’s just fetched. Ok great. Now we see the cross-group links showing all the dependencies for these new nodes.
The look of the graph is also greatly improved; lighter and cleaner. The problem with Generics is also fixed. Dev10 put Generics in their own group which didn’t make much sense. Generics are now integrated in with the rest of your code where they belong.
Let’s expand more of this graph. The meat of the application is in this main dll here.
Bottom Up Dependency Graphs (2:02)
Now top down dependency graphs like this are interesting, for a large project they can show you the big picture of what’s happening in your code which you may have never seen before. But sometimes you want a much smaller slice through your code. I’m super excited about the new Solution Explorer Integration.
You may have already noticed that Solution Explorer can now drill down inside classes and methods. You can also search. I’m interested in a feature of this software called “portfolio”, and it comes back with all the classes and methods that contain that string. Now if I select all of that you’ll see a new button that shows up that allows me to create a new dependency graph, with ancestors, of just the items I selected here. It’ll use the code index again, this time to add all the dependencies between these things.
That’s simply amazing. This is called a “bottom up dependency graph” as opposed to top down dependency graph you get from the Architecture menu.
Now you also can build bottom up graphs in an incremental way. For example, when I zoom in I see this method “GetInvestmentPortfolio” – I want to know more about it. That’s this method here (in the solution explorer) and I can right click and “find me everything that method Calls”, and see that information is now available in the solution explorer. I can select all of that and add that to the dependency graph, with ancestors. It uses the code index again and adds all those nodes, plus all the new dependencies between those nodes. Great!
Now I can look at the result, zoom in, and make some changes. I don’t need mscorlib dependencies so I can delete that. This class I will collapse. Now I’m starting to build up a story about this particular feature that makes sense to me as a developer.
What’s more, the new DGML document editor supports full editing. First off I can move nodes anywhere I want and all this is persisted, so if I save this graph, reload it, I see my layout the way I left it. In fact, I’ve already done that let me open it up. Here’s the same code and I’ve added some comments and a new group for an idea that could be added to the code in the future.
You can insert a new node using this hovering toolbar which allows you to add a node of the same type, you can also add a comment and that’s how I edited this graph very quickly and easily. You can also add new links.
You can also insert nodes using the keyboard. If you type the INSERT key a new node will show up where the mouse is. You can type ALT-INSERT to add an outgoing dependency here, if you type ALT+SHIFT+INSERT you get an incoming dependency.
When you’re done editing you can press the layout button the toolbar again to get a full graph layout. And if you didn’t mean to lose your custom layout you can hit undo to get back to the layout you had.
You can also edit the label of any node by just clicking on it twice and you can also add labels to links by pressing F2. And of course, now that you can select links, you can delete them. You can also select these nodes and put them in a new group.
You can also drag/drop a node across groups which will reparent that node in the target group. When you do that you will see that cross-group arteries are computed automatically and we’ve actually created a circular dependency between these groups. The analyzers by the way have been move to the legend add button – let’s add the circular analyzer and it shows us the problem that we’ve just created by highlighting these things in red. I can move the node back and that will fix the problem. This gives you the ability to do some interesting “what-if” analysis on your code.
By the way if you hold down the shift key when you move a node it actually bulldozes things out of the way instead of doing a drag/drop. That can be handy if you need to make a little more room to put stuff.
Quick Find (6:27)
The quick find dialog that you see in the text editor has been integrated. If I search for “investment” it takes me to the first hit and a really cool feature has been added here in the quick find command menu called “select all”. This is handy if you want to do an operation like “delete” to delete all the matching nodes. Of course, if I hit undo they all come back.
Fast Incremental Layout (6:55)
What’s happening here is a fast incremental layout – it’s not doing a full clean layout like you get from the toolbar layout buttons. That’s designed to give you good interactive performance when you’re editing these graphs.
Inline Toolbar (7:03)
You will also notice toolbar has been moved inside the graph document window– that’s really nice for multi-monitor situations where you want the toolbar to be available close to the graph you’re editing.
Zoom Widget (7:09)
There’s also a new zoom widget with a zoom to fit button. You can also zoom to fit any group by double clicking it which will center and zoom in on it. If you double click the graph background it will zoom to fit the entire graph.
Removed Some Unbaked Features (7:24)
You might have noticed that some features are missing. There used to be a “dependency matrix”, and “neighborhood” and “butterfly” modes on the toolbar. There was also a thing called “advanced selector” which showed up under the legend. These features weren’t being used very much and it’s nice to see that Microsoft can actually remove stuff instead of bloating the code with stuff that nobody uses.
Help Pages (7:47)
If you create a new directed graph document you’ll see some new information about what you can do including some help on how the mouse works, and there were some slight tweaks here from dev10, like I said you can actually pan and zoom without holding the control key down. And there’s some help for various keyboard shortcuts.
Lastly, more good news, when you create a graph like this and you want to share it with people, dev11 Professional SKU will be able to open this graph and look at it, and even edit it. The only feature missing from Pro SKU is the ability to reverse engineer new and create graphs from code using the code index.
So that’s about it! I think you’ll agree that the dependency graph feature just got a whole lot cooler.
The following DGML document maps out where the new features fit WhatsNew.dgml (26.80 kb)