Tasks are units of executable code used by MSBuild to perform build operations. The Task element specifies the task to run and the parameters to pass to the task. A library of common tasks is provided with MSBuild, and you can also write tasks yourself. For more information on tasks, see MSBuild Tasks and Task Element (MSBuild). For more information on the common tasks provided with MSBuild, see MSBuild Task Reference.
To compile a Visual C# project, use the Csc Task, and to compile a Visual Basic project, use the Vbc Task. Both of these tasks are part of the library of common tasks provided with MSBuild.
To add a task
Add a task as a child of a Target element.
Task elements do not use the word "Task" as their element name. Rather, the element name is the name of the task itself.
Add the necessary attributes for the task.
Some tasks accept parameters, which are passed to the task through attributes on the Task element.
The following example compiles a Visual C# project, passing the CSFile item collection to the Sources parameter of the task.
Note: |
|---|
Use the
@() notation to specify an entire item collection as a parameter.
|
<CSC Sources="@(CSFile)">...</CSC>
The following example compiles a Visual Basic project, passing the VBFile item collection to the Sources parameter of the task.
<VBC Sources="@(VBFile)">...</VBC>