OnError Element (MSBuild)
For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.
Causes one or more targets to execute, if the
ContinueOnError attribute is
false for a failed task.
<OnError ExecuteTargets="TargetName" Condition="'String A'=='String B'" />
The following sections describe attributes, child elements, and parent elements.
Condition to be evaluated. For more information, see Conditions.
The targets to execute if a task fails. Separate multiple targets with semicolons. Multiple targets are executed in the order specified.
|Target||Container element for MSBuild tasks.|
MSBuild executes the
OnError element if one of the
Target element's tasks fails with the
ContinueOnError attribute set to
false). When the task fails, the targets specified in the
ExecuteTargets attribute is executed. If there is more than one
OnError element in the target, the
OnError elements are executed sequentially when the task fails.
The following code executes the
TaskTwo tasks. If
TaskOne fails, MSBuild evaluates the
OnError element and executes the
<Target Name="ThisTarget"> <TaskOne ContinueOnError="ErrorAndStop"> </TaskOne> <TaskTwo> </TaskTwo> <OnError ExecuteTargets="OtherTarget" /> </Target>