Task Element (MSBuild) 

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

<Task Parameter1="Value1"... ParameterN="ValueN"
    Condition="'String A' == 'String B'" >
    <Output... />

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


Attribute Description


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


Optional attribute. A Boolean attribute that defaults to false if not specified. If ContinueOnError is false and a task fails, the remaining tasks in the Target element are not executed and the entire Target element is considered to have failed.

If this attribute is true, subsequent tasks in the Target element continue to execute even if the current task fails, and all errors from the task are treated as warnings.


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


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

Parent Elements

Element Description


Container element for MSBuild tasks.

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 MSBuild Tasks.

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)"
          DebugType="$(debuggingType)" >
        <Output TaskParameter="OutputAssembly"
                  ItemName="FinalAssemblyName" />

Community Additions