Click here to Skip to main content
Click here to Skip to main content
Technical Blog

Tagged as

How to build a specific project from a solution with MSBuild

, 17 Sep 2013 CPOL
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.

License

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

Share

About the Author

Vasil Trifonov
Software Developer (Senior) Telerik
Bulgaria Bulgaria
No Biography provided
Follow on   Twitter   Google+

Comments and Discussions

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