Architecture Tools in ReSharper 8

Like many people with very large Visual Studio projects, we in the ReSharper team wanted to get an overview of the 300+ project dependencies for ReSharper itself. Unfortunately, VS Ultimate gave us a representation that was rather difficult to interpret:

What we ended up doing is building our own tool for viewing project dependencies as well as comparing architectural snapshots as the solution continues to change and evolve.

Here’s how it works. First of all, with your solution open, go to ReSharper|Architecture|Build Architecture Graph:

ReSharper then goes through your solution and, without compiling anything, presents a dependency diagram of all the projects in the solution:

The great thing about the way R# does it is the fact that layout is calculated automatically to present an optimal illustration of dependencies between elements. ReSharper builds the dependency graph, and if the Show Code Metrics option is on (it is on by default) then reference analysis happens asynchronously — ReSharper analyzes the whole solution and indicates the strength of coupling between projects. This all happens on the background thread, so you can continue editing code, navigating etc. while ReSharper does its work.

There are two arrows linking the projects: black arrows show project references wheras grey arrows show unused references that can be safely removed without breaking the build.

The architecture diagram gets rendered for the scope you’ve selected in Solution Explorer: if you select just a folder with several projects, only those projects will be included. However, there is always a way to fine-tune which projects are represented by checking the appropriate boxes:

Ticking each of the boxes shows or hides the appropriate elements on the diagram. This allows us to instantly update the representation of connections between different subsystems as soon as they are checked or unchecked in the list on the left.

The toolbar shown above has several options for how information is presented on the graph. First of all, there are several ways of grouping information:

The above options are None (meaning no grouping is done), Solution folders for grouping by solution folder, and File structure for groupings based on actual directory structure and the projects’ position therein.

The following toolbar buttons are also available:

Collapse Graph and Expand Graph buttons let you collapse or expand an area where a grouping is used. A collapsed group looks simply like this:
As an alternative, one can simply double-click the + or - button on the group to expand or collapse it.

The Show/Hide Code Metrics button lets you show and hide metrics associated with the code. These metrics show used and unused references (black and grey arrows respectively) and also show the number of references from one project to another:

You can also select the indicator, right-click it and use Show Usages… to find out where these referencing calls actually occur.

Show Transitive References shows not only direct references but actually all transit references, so in addition to showing A → B → C, it will also show A → C on the diagram. This can lead to a very rich, circuit-like representation:

Save Architecture Graph lets you save the graph to a file.

Show Diff shows you a difference between two architecture graphs. In fact, you can also invoke this function (even without having a solution open) from the top-level menu:

The ability to save architecture graphs to a file allows the user to look at the difference between the architectural layout of the solution as it continues to evolve. The following illustrates the changes that have been made to a solution:

The above is an illustration of the evolution in one of ReSharper’s subsystems. Red boxes indicate parts that have been removed, whereas dark green ones indicate new parts that have been added. The same color scheme is also applied to references.

Lastly, keep in mind that project-level menus which can be invoked in Solution Explorer can be invoked on Architecture View nodes in the same manner:

As always, we hope that you find this feature useful — it is already in the latest EAP, so if you want to see it today, you know what to do. Keep in mind that this is a very fresh tool that we’ve built, and one that we’ll be sure to augment with additional architecture-related features in future releases.

34 Responses to Architecture Tools in ReSharper 8

Very nice – a quick observation (granted, this is early) – Azure Cloud projects don’t get picked up in this – if they are the current project scope, they are treated singularly, and if selected in the check diagram, they sit off to the side. True, there isn’t a “normal” reference as there is in “binary” projects, but it might be interesting to see if there’s a way to fit them as containers of some kind in this view, chaining through the roles they contain…

But when I saw this, a new product idea popped into my mind. Restructuring project structures.

There is an existing product that analyses the structure of an project and lets the user create a new better structure. It makes than a list of restructuring tasks to get to that new structure the resturucturing tasks are on the code level.

So my idea is can the architectural view be also used as an refactoring tool? Meaning

creating a new Box -> creating new Project or Namespace.
Moving classes from one box to another moving the classes from one project/Namespace into another project/Namespace. (Ala drag and drop).

This means that the boxes can be expanded with first level for example namespace hierarchy and further down to classes. Like zooming into the code like in restructure. This would be uber cool. I know that this won’t happen in Resharper 8 but I think this could be a good longterm idea.

Cool! But buggy. Is it worth writing up the bugs at this point, or is it still under heavy development and I can assume it’ll get more stable?

(Right-clicking an arrow and selecting “Find Usages” has no effect whatsoever; scroll bars don’t work as expected, and any attempt to use them just scrolls you toward the left/top; scroll wheel worked at first, but after I unchecked a bunch of projects, the scroll wheel stopped having any effect, even though the font was still about a 2-point size and unreadable.)

It’d also be great if I could hide all test projects at once — one click to uncheck any project that depends on NUnit.Framework.dll. But I’m not sure of the best way to do that without hard-coding a list of test frameworks.

@Joe
Thanks! Always great to know something is rated cool by you )
It certainly makes sense to file feature requests. As to bugs, I’d recommend letting a couple more nightly builds to come out, and if things don’t get better, start bombarding us with bug reports.

P.S. Just wondering, have the unit testing fixes you needed finally made it to EAP?

@Jura, yes they have — parameterized NUnit tests are much better in 8.0.8.197. I sent some feedback about one bug (might have been via “ReSharper misbehaves” rather than YouTrack) — extra crossed-out leaf nodes appear in the tree, sometimes not even parented to the test method they belong to — but so far it looks like that’s just cosmetic. The bugs I was running into (not all tests running, not all results showing in the tree) seem to be fixed, and I haven’t run into the problem with a class not getting added to the session. So far so good.

@Jura: Regarding the feature request of @Alex: you could use a similar UI like in this Silverlight demo here:http://www.yworks.com/products/yfilessilverlight/Demo.yFiles.Graph.Viewer.html
(take a look at the controls in the top left area of the view)
It’s similar to the way you can navigate in mapping services and very easy to implement with what you’ve got already!
That way you don’t have to add more and more icons to some toolbar and people know what to do with these controls, already.

This tool is somehow not working for me. I have a solution with three projects in it. The graph shows me the correct dependencies between those projects, but each project is just one node and I cannot expand the nodes. There are no buttons on those nodes themselves and the “expand graph” button on the left toolbar doesn’t do anything. Neither does it do anything in single project solutions. I always end up with just one node per project.
I am using the tool with 2012.

(Also after installing Resharper 8 my VS 2010 installation didn’t work anymore but crashed on startup, so I had to remove Resharper 8 from that installation.)

@Joseph at the moment, unfortunately, there isn’t – ReSharper uses the color settings that are defined for other elements, so there is nothing in Fonts & Colors to tweak. If this is critical for you, please request this feature on our issue tracker.

@Andreas @Sam actually, at the moment, ReSharper only highlights dependencies between projects, so you cannot drill down or “expand” a project. Rest assured, we are working on having class-level dependency diagrams too! Also, there is no ‘Build Graph’ option, the ‘View Project Dependencies’ is the item you want.

great tool!
I have a question though. I use the dark skin in Visual Studio 2013 and now the background of the architecture view is also dark. Which doesn’t look very nice. Do you happen to know which window type the architecture view uses? I can’t seem to find it.

I don’t think there’s a specific setting for the background of Arch View – it most likely uses the global UI color settings. Even if you found the right color switch, that would damage all the other window and might get the UI looking inconsistent.