Solution References, Dependency Inversion and Controlling Builds

Here’s a trick for your medium to large Visual Studio projects. In Tools/Options/Projects, Solutions/Build, Run there’s an option “Only build startup projects and dependencies on Run.” If you check this, it will do what you expect when you hit F5 – Visual Studio will only build the startup project and any direct dependencies. This is an individual machine setting, not a project setting.

But what if you are using dependency injection though MEF or an Inversion of Control container? In these scenarios, the main application probably references only a common assembly(ies) that have interface declarations. Implementations are in other assemblies that are not directly referenced. So, does that mean that if you use dependency injection on any project you can’t use the build limitation on any other solution?

Enter Solution/Project Dependencies! You might not have heard of this feature because it’s very well hidden in Visual Studio. I have heard these referred to as Solution References because the option appears on the Solution right click. “Project Dependencies…” have nothing to do with usual project references. This is a new kind of dependency indicator which is used for the minimal build. Creating this dependency does not create a project reference.

In case the Solution References dialog doesn’t seem intuitive, you select the project you want to work with in the combo box (A). This displays a series of check boxes for other projects in the solution (B).


A normal project entry is:

Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "Earth", "Earth\Earth.vbproj", "{8BFC7D54-B621-4E23-9CA9-101DDF9DFC79}"


If you have a dependency, this entry looks something like:

Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "HelloPlanet", "HelloPlanet\HelloPlanet.vbproj", "{D2CF0625-0549-49B4-99D5-C4CCC6068814}"

ProjectSection(ProjectDependencies) = postProject

{8BFC7D54-B621-4E23-9CA9-101DDF9DFC79} = {8BFC7D54-B621-4E23-9CA9-101DDF9DFC79}



Now, your dependency will be built along with any referenced projects!

Leave a Reply

Your email address will not be published. Required fields are marked *