How to: Build specific targets in solutions by using MSBuild.exe
You can use MSBuild.exe to build specific targets of specific projects in a solution.
To build a specific target of a specific project in a solution
At the command line, type
MSBuild.exe <SolutionName>.sln, where
<SolutionName>corresponds to the file name of the solution that contains the target that you want to execute.
Specify the target after the
-target:switch in the format <ProjectName>:<TargetName>. If the project name contains any of the characters
', replace them with an
_in the specified target name.
The following example executes the
Rebuild target of the
NotInSlnFolder project, and then executes the
Clean target of the
InSolutionFolder project, which is located in the NewFolder solution folder.
msbuild SlnFolders.sln -target:NotInSlnfolder:Rebuild;NewFolder\InSolutionFolder:Clean
Building a specific target also triggers other dependent targets to build.
If you would like to examine the solution project, you can use a debugging option provided by MSBuild to do so. Set the environment variable
MSBUILDEMITSOLUTION=1 and build your solution. This will produce an MSBuild file named <SolutionName>.sln.metaproj that shows MSBuild's internal view of the solution at build time. You can inspect this view to determine what targets are available to build, and other configuration details.
Do not build with this environment variable set unless you need this internal view. This setting can cause problems building projects in your solution. Look in the binary log instead.
Submit and view feedback for