Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
.NET Framework 3.5
MSBuild Reference
 OnError Element (MSBuild)
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
.NET Framework General Reference
OnError Element (MSBuild)

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.

Attributes

Attribute

Description

Condition

Optional attribute.

Condition to be evaluated. For more information, see MSBuild Conditions.

ExecuteTargets

Required attribute.

The targets to execute if a task fails. Separate multiple targets with semicolons. Multiple targets are executed in the order specified.

Child Elements

None.

Parent Elements

Element

Description

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. For more information, see MSBuild Targets.

The following code executes the TaskOne and TaskTwo tasks. If TaskOne fails, MSBuild evaluates the OnError element and executes the OtherTarget target.

<Target Name="ThisTarget">
    <TaskOne ContinueOnError="false">
    </TaskOne>
    <TaskTwo>
    </TaskTwo>
    <OnError ExecuteTargets="OtherTarget" />
</Target>
Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
The element <OnError> must be last under element <Target>      Sergei M. Zinovyev   |   Edit   |   Show History
The element <OnError> must be last under element <Target>.
Flag as ContentBug
Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker