UsingTask Element (MSBuild)
Maps the task that is referenced in a Task element to the assembly that contains the task implementation.
Attributes and Elements
The following sections describe attributes, child elements, and parent elements.
Either the AssemblyName attribute or the AssemblyFile attribute is required.
The name of the assembly to load. The AssemblyName attribute accepts strong-named assemblies, although strong-naming is not required. Using this attribute is equivalent to loading an assembly by using the Load method in .NET.
You cannot use this attribute if the AssemblyFile attribute is used.
Either the AssemblyName or the AssemblyFile attribute is required.
The file path of the assembly. This attribute accepts full paths or relative paths. Relative paths are relative to the directory of the project file or targets file where the UsingTask element is declared. Using this attribute is equivalent to loading an assembly by using the LoadFrom method in .NET.
You cannot use this attribute if the AssemblyName attribute is used.
Specifies the class in the assembly that is responsible for generating instances of the specified Task name. The user may also specify a TaskBody as a child element that the task factory receives and uses to generate the task. The contents of the TaskBody are specific to the task factory.
The name of the task to reference from an assembly. If ambiguities are possible, this attribute should always specify full namespaces. If there are ambiguities, MSBuild chooses an arbitrary match, which could produce unexpected results.
The condition to evaluate. For more information, see MSBuild Conditions.
The set of parameters that appear on the task that is generated by the specified TaskFactory.
The data that is passed to the TaskFactory to generate an instance of the task.
Required root element of an MSBuild project file.
Environment variables, command-line properties, and project-level properties can be referenced anywhere in the UsingTask element if it appears in the project file either explicitly or through an imported project file. For more information, see MSBuild Tasks.
Project-level properties have no meaning if the UsingTask element is coming from one of the .tasks files that are globally registered with the MSBuild engine. Project-level properties are not global to MSBuild.
In MSBuild 4.0, using tasks can be loaded from .overridetask files.
The following example shows how to use the UsingTask element with an AssemblyName attribute.
<UsingTask TaskName="MyTask" AssemblyName="My.Assembly" TaskFactory="MyTaskFactory"> <ParameterGroup> <Parameter1 ParameterType="System.String" Required="False" Output="False"/> <Parameter2 ParameterType="System.Int" Required="True" Output="False"/> ... </ParameterGroup> <TaskBody> ... Task factory-specific data ... </TaskBody> </UsingTask>
The following example shows how to use the UsingTask element with an AssemblyFile attribute.
<UsingTask TaskName="Email" AssemblyFile="c:\myTasks\myTask.dll" />