UsingTask Element (MSBuild)
Maps the task referenced in a Task element to the assembly that contains the task's implementation.
<Project>
<UsingTask>
<UsingTask TaskName="TaskName"
AssemblyName = "AssemblyName"
Condition="'String A'=='String B'" />
Attributes and Elements
The following sections describe attributes, child elements, and parent elements.
Attributes
Attribute |
Description |
---|---|
AssemblyName |
Either the AssemblyName or the AssemblyFile attribute is required. The name of the assembly to load. The AssemblyName attribute accepts strong named assemblies although it is not required. Using this attribute is equivalent to loading an assembly via the Load method in the .NET Framework. You cannot use this attribute if the AssemblyFile attribute is used. |
AssemblyFile |
Either the AssemblyName or the AssemblyFile attribute is required. The file path to the assembly. This attribute accepts both full and relative paths. Relative paths are relative to the directory of the project or targets file where the UsingTask element is declared. Using this attribute is equivalent to loading an assembly via the LoadFrom method in the .NET Framework. You cannot use this attribute if the AssemblyName attribute is used. |
TaskName |
Required attribute. 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. |
Condition |
Optional attribute. Condition to evaluate. For more information, see MSBuild Conditions. |
Child Elements
None.
Parent Elements
Element |
Description |
---|---|
Required root element of an MSBuild project file. |
Remarks
Environment variables, command-line and project-level properties can be referenced anywhere inside of the UsingTask element as long as it appears inside of the project file, either explicitly or via an imported project file. For more information, see MSBuild Tasks.
Note
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. These properties are not global to MSBuild.
Example
The following example shows how to use the UsingTask element with an AssemblyName attribute.
<UsingTask TaskName="Microsoft.Build.Tasks.Csc"
AssemblyName="Microsoft.Build.Tasks" />
The following example shows how to use the UsingTask element with an AssemblyFile attribute.
<UsingTask TaskName="Email"
AssemblyFile="c:\myTasks\myTask.dll" />
See Also
Concepts
MSBuild Project File Schema Reference