Target Element (MSBuild) 

Contains a set of tasks for MSBuild to execute sequentially.

<Target Name="Target Name"
        Condition="'String A' == 'String B'">
    <Task>... </Task>
    <OnError... />

The following sections describe attributes, child elements, and parent elements.


Attribute Description


Required attribute.

The name of the target.


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.


Optional attribute.

The item inputs for this target. Items inside this attribute are used as the inputs in the top level dependency analysis.


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.


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.

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.

The following code example shows a Target element that executes the Csc task.

<Target Name="Compile" DependsOnTarget="Resources" >
    <Csc Sources="@(CSFile)"
          DebugType="$(debuggingType)" >
        <Output TaskParameter="OutputAssembly"
                  ItemName="FinalAssemblyName" />

Community Additions