This document outlines how to create and use inline tasks in MSBuild. It discusses the structure of an inline task including the UsingTask attributes, elements, and Code element. It provides examples of simple "Hello World" and BMI calculation inline tasks to demonstrate how input and output parameters are defined and used. The examples show how to perform basic operations and return output within an inline task coded directly in the MSBuild project file.
2. Outline
• The Structure of an Inline Task
• Input and Output Parameters
• UsingTask Attributes
• UsingTask Elements
• Code Element
• Examples
– Hello world
– BMI
2
4. UsingTask Attributes
<UsingTask • TaskName
TaskName="DoNothing"
• TaskFactory
TaskFactory="CodeTaskFactory"
– The TaskFactory attribut
AssemblyFile=
"$(MSBuildToolsPath)Microsoft.Build.Tasks.v4.0.dll"> e names the class that
</UsingTask> implements the inline
task factory
• AssemblyFile
– The AssemblyFile attribu
te gives the location of
the inline task factory.
4
5. UsingTask Elements
<UsingTask …> • ParameterGroup
<ParameterGroup /> – Input and output
<Task> paramerters
<Reference Include="" />
• Reference
<Using Namespace="" />
– Specifies references to
</Task>
the .NET assemblies that
</UsingTask>
you are using in your code.
• Using
– The Using element lists the
namespaces that you want
to access.
5
6. Code Element
<UsingTask …> • Type
<Task> – Class
<Code
– Method
Type="Fragment"
– Fragment
Language="cs">
<![CDATA[ • Language
Log.LogError("Hello, world!");
– cs for c#
]]>
– vb for Visual Basic
</Code>
</Task> – js for JScript
</UsingTask>
6
Alternatively, you can use the Source attribute of the Code element to specify the location of a file that contains the code for your task. The code in the source file must be of the type that is specified by the Type attribute. If the Source attribute is present, the default value of Type is Class . If Source is not present, the default value is Fragment .
Required is an optional attribute that is false by default Output is an optional attribute that is false by default