Click here to Skip to main content
13,255,340 members (56,339 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


4 bookmarked
Posted 17 Sep 2013

How To Build A Specific Project From A Solution with MSBuild

, 17 Sep 2013
Rate this:
Please Sign up or sign in to vote.
How to build a specific project from a solution with MSBuild

Sometimes you want to build only a single project, or a list of projects from a solution without building the whole solution with MSBuild.

To do so, you can use custom build targets. You need to add a custom build target for every project you want to build containing the relative path in solution structure of the project (.csproj/.vproj). Another thing you need to have in mind is that the dots(.) in the project name should be replaced with underscores(_). You can clean or rebuild adding :Clean, :Rebuild at the end of the target.

However if you can check all the MSBuild targets used from the solution. As you may know, when running MSBuild command against a solution file in-memory, it is converted to an actual MSBuild project named [SolutionName].sln.metaproj. You can add an environment variable named msbuildemitsolution and set its value to 1 and run MSBuild from command line. Another option is to add /p:msbuildemitsolution=1 to the passed parameters to the build. This will generate the .metaproj file where you can find all the needed targets.

Let's illustrate all the above with a simple example. Here is a simple project structure:

If we want to build Project.Four and rebuild ProjectTwo, we need to call MSBuild with the following arguments:

msbuild BuildSpecificProjectsFromASolution.sln /t:"Folder2\Project_Four";"ProjectTwo:Rebuild"

You can find the sample solution here.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Vasil Trifonov
Software Developer (Senior) Telerik
Bulgaria Bulgaria
No Biography provided

You may also be interested in...


Comments and Discussions

-- There are no messages in this forum --
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.171114.1 | Last Updated 17 Sep 2013
Article Copyright 2013 by Vasil Trifonov
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid