Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I batch based on a Property (not just Items)?

Tags:

msbuild

I have a property group, like so:

<PropertyGroup>
    <Platform>Win32;x64</Platform>
</PropertyGroup>

And I want to batch in an Exec task, like so:

<Exec Command='devenv MySolution.sln /Build "Release|%(Platform)"' />

But of course, as written I get an error:

error MSB4095: The item metadata %(Platform) is being referenced without an item name.  Specify the item name by using %(itemname.Platform).

Can I batch tasks on properties that are lists? I suppose I could hack it by creating a placeholder ItemGroup with metadata and batch on that.

like image 597
Josh Buedel Avatar asked Dec 12 '22 23:12

Josh Buedel


1 Answers

Since your property is separated by a ; you can directly create an item from it and then batch from that. For example.

<Project ToolsVersion="3.5" DefaultTargets="Demo" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Platform>Win32;x64</Platform>
  </PropertyGroup>

  <Target Name="Demo">
    <ItemGroup>
      <_PlatFormItem Include="$(Platform)"/>
    </ItemGroup>

    <Message Text="Platform: $(Platform)"/>
    <Message Text="_PlatFormItem: @(_PlatFormItem)"/>
    <Message Text="Platform.Identity: %(_PlatFormItem.Identity)"/>

    <Exec Command='devenv MySolution.sln /Build "Release|%(_PlatFormItem.Identity)"' />
  </Target>

</Project>

Here I'm batching using %(_PlatformItem.Identity) because Identity has the values (Win32 and x64).

like image 87
Sayed Ibrahim Hashimi Avatar answered Feb 08 '23 19:02

Sayed Ibrahim Hashimi