Target Element (MSBuild)
Contains a set of tasks for MSBuild to execute sequentially.
<Target Name="Target Name"
DependsOnTargets="DependentTarget"
Inputs="Inputs"
Outputs="Outputs"
Condition="'String A' == 'String B'">
<Task>... </Task>
<OnError... />
</Target>
Attributes and Elements
The following sections describe attributes, child elements, and parent elements.
Attributes
Attribute | Description |
---|---|
Name |
Required attribute. The name of the target. |
DependsOnTargets |
Optional attribute. The targets that must be executed before this target can execute or top level dependency analysis can occur. Multiple targets are separated by semicolons. |
Inputs |
Optional attribute. The item inputs for this target. Items inside this attribute are used as the inputs in the top level dependency analysis. |
Outputs |
Optional attribute. The expected outputs of this target. You can apply transforms to the input items to generate the output items. For more information on transforms, see MSBuild Transforms. |
Condition |
Optional attribute. Condition to be evaluated. If the condition evaluates to false, the target will not execute the body of the target or any targets set in the DependsOnTargets attribute. For more information about conditions, see MSBuild Conditions. |
Child Elements
Element | Description |
---|---|
Creates and executes an instance of an MSBuild task. There may be zero or more tasks in a target. |
|
Causes one or more targets to execute if the ContinueOnError attribute is false for a failed task. There may be zero or more OnError elements in a target. If OnError elements are present, they must be the last elements in the Target element. |
Parent Elements
Element | Description |
---|---|
Required root element of an MSBuild project file. |
Remarks
The first target to execute is specified at runtime. Targets can have dependencies on other targets. For example, a target for deployment depends on a target for compilation. The MSBuild engine executes dependencies in the order they appear in the DependsOnTargets attribute from left to right. For more information, see MSBuild Targets.
A target is only executed once during a build, even if more than one target has a dependency on it.
If a target is skipped because its Condition attribute evaluates to false, it can still be executed if it is invoked later in the build, and its Condition attribute evaluates to true at that time.
Example
The following code example shows a Target element that executes the Csc task.
<Target Name="Compile" DependsOnTarget="Resources" >
<Csc Sources="@(CSFile)"
TargetType="library"
Resources="@(CompiledResources)"
EmitDebugInformation="$(includeDebugInformation)"
References="@(Reference)"
DebugType="$(debuggingType)" >
<Output TaskParameter="OutputAssembly"
ItemName="FinalAssemblyName" />
</Csc>
</Target>