ערוך

שתף באמצעות


Task element of Target (MSBuild)

Creates and executes an instance of an MSBuild task. The element name is determined by the name of the task being created.

<Project> <Target>

Syntax

<Task Parameter1="Value1"... ParameterN="ValueN"
    ContinueOnError="WarnAndContinue/true/ErrorAndContinue/ErrorAndStop/false"
    Condition="'String A' == 'String B'" >
    <Output... />
</Task>

Attributes and elements

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

Attributes

Attribute Description
Condition Optional attribute. Condition to be evaluated. For more information, see Conditions.
ContinueOnError Optional attribute. Can contain one of the following values:

- WarnAndContinue or true. When a task fails, subsequent tasks in the Target element and the build continue to execute, and all errors from the task are treated as warnings.
- ErrorAndContinue. When a task fails, subsequent tasks in the Target element and the build continue to execute, and all errors from the task are treated as errors.
- ErrorAndStop or false (default). When a task fails, the remaining tasks in the Target element and the build aren't executed, and the entire Target element and the build is considered to have failed.

Versions of the .NET Framework before 4.5 supported only the true and false values.

For more information, see How to: Ignore errors in tasks.
Parameter Required if the task class contains one or more properties labeled with the [Required] attribute.

A user-defined task parameter that contains the parameter value as its value. There can be any number of parameters in the Task element, with each attribute mapping to a .NET property in the task class.

Child elements

Element Description
Output Stores outputs from the task in the project file. There may be zero or more Output elements in a task.

Parent elements

Element Description
Target Container element for MSBuild tasks.

Remarks

A Task element in an MSBuild project file creates an instance of a task, sets properties on it, and executes it. The Output element stores output parameters in properties or items to be used elsewhere in the project file.

If there are any OnError elements in the parent Target element of a task, they will still be evaluated if the task fails and ContinueOnError has a value of false. For more information on tasks, see Tasks.

Example

The following code example creates an instance of the Csc task class, sets six of the properties, and executes the task. After execution, the value of the OutputAssembly property of the object is placed into an item list named FinalAssemblyName.

<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>

See also