A while ago there was a question on Stack Overflow about how one could go about mapping the dependencies between Visual Studio projects and solutions (see here: http://stackoverflow.com/questions/471154/how-can-i-map-out-which-visual-studio-solutions-use-which-projects). At the time I had been doing a little bit of work with GraphViz, and suggested that it could be used for the diagramming part. The problem itself seemed kind of interesting, so I decided to implement a solution myself for kicks.
My tool takes a visual studio solution, and produces a PNG image showing the dependencies between the projects in that solution. Pretty basic stuff, but it involves:
- Parsing a Visual Studio .sln file.
- Parsing the .csproj files referenced in the .sln file. (I don’t think it is C# specific but have not tested it on other project types).
- Creating an in memory representation of the solution structure.
- Creating a graph in QuickGraph to represent that structure.
- Creating a dot file for GraphViz from that graph.
- Pass that file to GraphViz and display the output.
This results in something like this:

The source code is here.
Updated: I’ve put this project on GitHub, and added Melle’s changes to it. You can find it here.
Feel free to do what you like with it, it only took me about 3-4 hours to get it all working. However if you actually use it as part of another project, please leave a comment.
You’ll need the latest version of GraphViz, which can be downloaded from here: http://graphviz.org/Download_windows.php. I’ve been using the development snapshot, but the stable release should be fine. When my tool first runs, it’ll ask you for the location of graphviz. You need to specify the location of dot.exe, which by default is in %Program Files%\GraphViz 2.21\bin.
Standard disclaimer: I’m not responsible for anything that goes wrong when using this thing. You have the source, you should check it out before running it. If it wipes your system and kills your firstborn child feel free to let me know, but don’t expect me to do anything about it.
5 Comments, Comment or Ping
I’ve created a simular tool, source is available here
http://code.google.com/p/depcharter/
January 21st, 2010
Glad you found that project useful.
January 23rd, 2010
Hi Jamie,
Great tool, resulting in a spaghetti-graph (in our case at least :-)
Anyway, just to let you know; when a solution has solution-folders than it crashes, I had to change the code so that it only takes the csproj files of the solution like this:
if (line.StartsWith(“Project”) && line.Contains(“.csproj”))
{
ProjectLoader project = ProjectProjectLine(line, filebase);
projects[project.ProjectIdentifier()] = project;
line = reader.ReadLine();
}
else
{
line = reader.ReadLine();
continue;
}
March 10th, 2010
Hi Melle,
Thanks for the mention. I’ve updated that project and put it up on GitHub at http://github.com/jamiepenney/VS-Dependency-Viewer. I’m glad someone has a use for these little projects I create. I might do a little more work to make it easier to do the colouring you’ve done in your blog post – did you add this manually to the .dot file or did you do some analysis in the project loading code?
I tried to post this comment to your blog, but the spam protection wouldn’t let me through.
Cheers, Jamie
March 14th, 2010
Reply to “Viewing Dependencies Between Projects in Visual Studio”