Skip to content

Instantly share code, notes, and snippets.

@esfand
Created March 20, 2010 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save esfand/338646 to your computer and use it in GitHub Desktop.
Save esfand/338646 to your computer and use it in GitHub Desktop.
MSBuild Inline Task
<?xml version="1.0" encoding="utf-8"?>
<!-- Sample Demonstrates Inline Tasks © 2010 Sayed Ibrahim Hashimi -->
<Project ToolsVersion="4.0"
DefaultTargets="Demo"
xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask
TaskName="CreateGuid02"
TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll" >
<ParameterGroup>
<NumToCreate ParameterType="System.Int32" Required="true" />
<Guids ParameterType="System.String[]" Output="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
List<string> guids = new List<string>();
for (int i = 0; i < NumToCreate; i++) {
guids.Add(Guid.NewGuid().ToString());
}
Guids = guids.ToArray();
]]>
</Code>
</Task>
</UsingTask>
<Target Name="Demo">
<CreateGuid02 NumToCreate="1">
<Output ItemName="Id01" TaskParameter="Guids" />
</CreateGuid02>
<Message Text="Id01: @(Id01)" Importance="high" />
<CreateGuid02 NumToCreate="4">
<Output ItemName="Id02" TaskParameter="Guids" />
</CreateGuid02>
<Message Text=" " Importance="high" />
<Message Text="Id02: @(Id02)" Importance="high" />
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment