5
votes

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
1

1 Answers

6
votes

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>