PowerShellTaskFactory Class | MSBuild Extension Pack Help 4.0.12.0 |
A task factory that enables inline PowerShell scripts to execute as part of an MSBuild-based build.
Inheritance Hierarchy
Namespace: MSBuild.ExtensionPack.TaskFactory
Assembly: MSBuild.ExtensionPack.TaskFactory.PowerShell (in MSBuild.ExtensionPack.TaskFactory.PowerShell.dll) Version: 4.0.0.0
The PowerShellTaskFactory type exposes the following members.
Constructors
Name | Description | |
---|---|---|
PowerShellTaskFactory |
Methods
Name | Description | |
---|---|---|
CleanupTask |
Cleanup the Task
| |
CreateTask |
Create a Task.
| |
GetTaskParameters |
Get the Task Parameters
| |
Initialize |
Initialize the Task Factory
|
Properties
Name | Description | |
---|---|---|
FactoryName |
Get the Factory Name
| |
TaskType |
The type of Task
|
Examples
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003"> <PropertyGroup> <AssemblyFile>$(MSBuildProjectDirectory)\..\MSBuild.ExtensionPack.TaskFactory.PowerShell.dll</AssemblyFile> <AssemblyFile Condition="Exists('$(MSBuildProjectDirectory)\..\..\..\BuildBinaries\MSBuild.ExtensionPack.TaskFactory.PowerShell.dll')">$(MSBuildProjectDirectory)\..\..\..\BuildBinaries\MSBuild.ExtensionPack.TaskFactory.PowerShell.dll</AssemblyFile> </PropertyGroup> <UsingTask TaskFactory="PowershellTaskFactory" TaskName="Add" AssemblyFile="$(AssemblyFile)"> <ParameterGroup> <First Required="true" ParameterType="System.Int32" /> <Second Required="true" ParameterType="System.Int32" /> <Sum Output="true" /> </ParameterGroup> <Task> <!-- Make this a proper CDATA section before running. --> CDATA[ $log.LogMessage([Microsoft.Build.Framework.MessageImportance]"High", "Hello from PowerShell! Now adding {0} and {1}.", $first, $second) if ($first + $second -gt 100) { $log.LogError("Oops! I can't count that high. :(") } $sum = $first + $second ]] </Task> </UsingTask> <UsingTask TaskFactory="PowershellTaskFactory" TaskName="Subtract" AssemblyFile="$(AssemblyFile)"> <ParameterGroup> <First Required="true" ParameterType="System.Int32" /> <Second Required="true" ParameterType="System.Int32" /> <Difference Output="true" /> </ParameterGroup> <Task> <!-- Make this a proper CDATA section before running. --> CDATA[ $difference = $first - $second ] </Task> </UsingTask> <PropertyGroup> <!-- Try making the sum go over 100 to see what happens. --> <FirstNumber>5</FirstNumber> <SecondNumber>8</SecondNumber> </PropertyGroup> <Target Name="Build"> <Add First="$(FirstNumber)" Second="$(SecondNumber)"> <Output TaskParameter="Sum" PropertyName="MySum" /> </Add> <Message Importance="High" Text="The $(FirstNumber) + $(SecondNumber) = $(MySum)" /> <Subtract First="$(FirstNumber)" Second="$(SecondNumber)"> <Output TaskParameter="Difference" PropertyName="MyDifference" /> </Subtract> <Message Importance="High" Text="The $(FirstNumber) - $(SecondNumber) = $(MyDifference)" /> </Target> </Project>
See Also