How to translate from Properties to Items?

I have a property that has comma-separated values, like "A,B,C,D" and I need to pass it to another target. My current solution is to declare it as items and the pass it to msbuild with batching:

<PropertyGroup>
   <MyProperties>A,B,C,D</MyProperty>
</PropertyGroup>

<
ItemGroup
>
   <
MyPropertiesAsItems Include="A;B;C;D"
/>
</ItemGroup
>

<Target Name="MyTarget">
   <
MSBuild Projects="$(MSBuildProjectFile)"
 
                 
Properties="MyProperty=%(MyPropertiesAsItems.Identity)"
                 
Targets="MyOtherTarget"/>
</Target>

The problem with this is the redundancy in having to declare both the property and the item. I would like to be able to convert from the property to the item. One possiblity is to create a custom task for it, but I'd like to avoid that.
Does anyone can think of any other way to do this


Best Regards,
Gustavo Guerra



Answer this question

How to translate from Properties to Items?

  • Bernardm1

    I want to avoid from making custom task because of deployment. Anyway, I found a way to do what I wanted without needing these properties/items.

    BTW, in what exactly does VS use the AvailablePlatforms Property It doesn't seem to need it to populate the platforms in the project properties drop-down menu.

    Regards,
    Gustavo Guerra

  • AndyDragon

    Visual Studio uses the AvailablePlatforms property to populate the list of platform choices when adding a new platform to your project.  To try this out, follow these steps:

    1.)  Modify Microsoft.Common.targets to have a new value for AvailablePlatforms.  For example,

      <PropertyGroup>
          <AvailablePlatforms>Any CPU,x86,x64,Itanium,MyNewPlatform</AvailablePlatforms>
      </PropertyGroup>

    2.)  Inside Visual Studio, create a new C# Console Application.

    3.)  Right-click on the Solution node in the Solution Explorer, and select "Configuration Manager ...".

    4.)  In the grid of projects, find the console application project, and in the "Platform" column, click the down-arrow button and select "<New...>".

    5.)  In the "New Platform" combo box, you should now see "MyNewPlatform" shown in the list.

    --Rajeev

  • David Daniel

    Humm, I figured it now. I was thinking of the other Platform kind (AnyCPU), I hadn't noticed this one (the Any CPU,x86, x64, ...)

    Thanks,
    Gustavo Guerra

  • ShaTari

    No, the property isn't defined by me, it's the AvailablePlatforms property. I want to have a task that batch builds for each platform

    Gustavo Guerra

  • Roberto_1959

    Thought about this for a while - but couldn't come up with an easy way to do this.  Now that I think about it, that list should really have been semi-colon separated.  The interesting aspect though is that that property is only used by Visual Studio (and not used anywhere in the build actually).

    My recommendation would be to write a quick "Split" task that can create an item list for you.

    Great questions by the way - keep 'em coming.

    Thanks.
    Faisal Mohamood

  • Stef76

    Is it possible for you to declare the Item itself as the set of separated values, instead of defining the property first

    <ItemGroup>
       <MyItem Include="A;B;C;D" />
    </ItemGroup>

    You can then very easily use a transform to convert that into a comma separated list - as this:

    <Message Text="Comma Separated List: @(MyItem->'%(Identity)',',')" />

    You can also create a property dynamically using the CreateProperty task.

    <CreateProperty Value="@(MyItem->'%(Identity)',',')">
       <Output TaskParameter="Value" PropertyName="MyProperties" />
    </CreateProperty>

    -faisal

  • How to translate from Properties to Items?