Alphapage
Alphapage

Reputation: 919

2 tasks inside a msbuild loop

I'm trying to achieve something like this:

<ItemGroup>
       <Projects Include="projectpath1"/>
       <Projects Include="projectpath2"/>
       ...
<ItemGroup/>

// foreach project {
<GetCss Project=%Project.Identity CssOutputs=@CssFiles/>
<MergeCss CssInputs=@CssFiles CssOutputFile="test.css"/>
 // } execute GetCss then MergeCss foreach project 

GetCss and MergeCss are custom inline tasks.

I don't want:

// foreach project {
    <GetCss Project=%Project.Identity CssOutputs=@CssFiles/>
// }
// foreach project {
    <MergeCss CssInputs=@CssFiles CssOutputFile="test.css"/>
  // }

Thanks in advance for your help.

Upvotes: 0

Views: 76

Answers (1)

Michael
Michael

Reputation: 1282

Based on your code, it looks like you'd want to perform target batching so that you could call both of the inline tasks for each of your Projects items. Here's an example of a batched target named GetAndMergeCss, with the assumption that your GetCss inline task takes a string for an input and the CssFiles listed for CssOuputs are MSBuild items to be consumed by your MergeCss inline task:

<ItemGroup>
  <Projects Include="projectpath1"/>
  <Projects Include="projectpath2"/>
</ItemGroup>

<Target Name="GetAndMergeCss" Outputs="%(Projects.Identity)">

  <PropertyGroup>
    <ThisProjectIdentity>%(Projects.Identity)</ThisProjectIdentity>
  </PropertyGroup>

  <Message Text="Preparing to get and merge css for project:  $(ThisProjectIdentity)" />

  <GetCss Project="$(ThisProjectIdentity)" CssOutputs="@(CssFiles)"/>
  <!--Or this works too...<GetCss Project="%(Projects.Identity)" CssOutputs="@(CssFiles)"/>-->

  <MergeCss CssInputs="@(CssFiles)" CssOutputFile="test.css"/>

</Target>

Upvotes: 2

Related Questions