Specify Which Target to Build First
A project file can contain one or more Target elements that define how the project is built. Each target contains a set of tasks that the .NET Build Engine runs sequentially. You can specify which target to build first by either defining a target as the default target in the project file or using the command line switch /target to specify a target at the time that you build the project.
In this example, the "Hello World" project file contains two targets: Compile and Clean.
DefaultTargets Attribute
In the "Hello World" project file, Compile is used automatically because it is defined as the default target in the root element Project by using the
DefaultTargets attribute:
<Project
DefaultTargets = "Compile">
You can specify more than one default target; list the targets in order and use a semicolon to separate the list of targets. For example, to use the target Clean then the target Compile, type:
<Project
DefaultTargets = "Clean;Compile">
/target
If a default target is not defined in the project file, or if you do not want to use that default target, you can use the command line switch /target to specify a different target. For example, to use the Clean target instead of the Compile target for the "Hello World" project, type:
msbuild <file name>.proj /target:Clean
The /target switch can be shortened to /t and can specify more than one target, for example, to use the target Clean then the target Compile, type:
msbuild <file name>.proj /t:Clean;Compile
You can use either a comma or a semicolon to separate a list of targets. Alternatively, you can repeat the switch, for example:
msbuild <file name>.proj /t:Clean /t:Compile
If the project file does not contain a
DefaultTargets attribute in the
Project element and no target is specified at the command line,
MSBuild builds the first target that occurs in the project file.
Download Code - C#Download Code - VB