Tip #109 Did you know … How to speed up build time by *only* building the currently selected project in a multi-project solution?

When working with a solution that contains numerous projects, I find myself often wanting to only build and run the currently selected project. Other projects in the solution might have build errors that I don’t want to resolve at the current time. By default though, trying to do a CTRL+F5 on the currently selected project will cause Visual Studio (VS) to build all of the projects in a solution.

Let’s walk through how to tweak this behavior.

We’ll start with a solution that has two projects – WebApplication_1 and WebApplication_2.

First, we’ll configure VS to set the “Startup Project” as the “Current selection” in the “Solution Explorer” window. You can configure this via the Properties settings of a solution file (right click on it) and then setting the “Startup Project” to “Current selection”. Now, the project highlighted in the “Solution Explorer” is the one that’s run by default.

CurrentSelection


Let’s run WebApplication_1 by selecting it in Solution Explorer.

TwoProjectsInSolution


Next, we’ll do a CTRL+F5. The VS output window shows:

Build


Notice that we’ve built two projects yet I only wanted to run one of them and there’s no dependency configured between the two. Visual Studio by default builds all of the projects in a solution. You can imagine the delay you might incur if you had a solution with numerous projects and if some of these included pre- or post-build tasks.

Thankfully, there’s a way to change this.

Under “Tools –> Options”, “Projects and Solutions” (might need to check “Show all settings”), there’s a setting called “Only build startup projects and dependencies on Run”. Check that box.

OnlyBuild


Now, if we return to our solution and repeat trying to run just WebApplication_1, we see that VS only builds that project and not the other one as well.

BuildJustOne


Hope this helps.

Mark Berryman – ASP.NET Team

No Comments