Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MSBuild Task Batching for multiple tasks

Tags:

msbuild

I have an MSBuild task with 2 steps, which for simplicity I'm replacing with <Message>. There are 2 modes which must be passed to the steps as parameters. These 2 steps must be run as a unit for each mode. I tried to use task batching as shown below.

<ItemGroup>
  <Mode Include="Mode1" />
  <Mode Include="Mode2" />
</ItemGroup>

<Target Name="Build">
  <Message Text="Step1: %(Mode.Identity)" />
  <Message Text="Step2: %(Mode.Identity)" />
</Target>

The problem is that each step is treated separately, generating the following output:

Step1: Mode1
Step1: Mode2
Step2: Mode1
Step2: Mode2

Is there any way to achieve this?

Step1: Mode1
Step2: Mode1
Step1: Mode2
Step2: Mode2
like image 459
ytran Avatar asked Sep 27 '13 21:09

ytran


1 Answers

You are currently doing Task Batching. What you want to do is Target Batching by specifying the outputs of the Target.

<ItemGroup>
  <Mode Include="Mode1" />
  <Mode Include="Mode2" />
</ItemGroup>

<Target Name="Build" Outputs="%(Mode.Identity)" >
  <Message Text="Step1: %(Mode.Identity)" />
  <Message Text="Step2: %(Mode.Identity)" />
</Target>
like image 152
Aaron Carlson Avatar answered Nov 15 '22 15:11

Aaron Carlson