I wonder why in the following code, MsBuild refuses to set the Suffix Metadata. It does work with a CreateItem task instead of the ItemGroup Declaration (because CreateItem is computed at build time) but I can't do this here because this code is in a "property file" : the project has no target, it's just a bunch of properties/items I include in real projects.
<ItemGroup>
<Layout Include="Bla">
<PartnerCode>bla</PartnerCode>
</Layout>
<Layout Include="Bli">
<PartnerCode>bli</PartnerCode>
</Layout>
</ItemGroup>
<ItemGroup Condition="'$(LayoutENV)'=='Preprod'">
<LayoutFolder Include="Preprod">
<Destination>..\Compil\layout\pre\</Destination>
</LayoutFolder>
</ItemGroup>
<ItemGroup>
<Destinations Include="@(LayoutFolder)" >
<Suffix>%(Layout.PartnerCode)</Suffix>
</Destinations>
</ItemGroup>
Destinations is well built but the Suffix Metadata is not set.
As for now, I have duplicated the Destinations Definition in every project I needed it but it's not very clean. If someone has a better solution, I'm interested!
It appears that I try to set Metadata dynamically outside a target which is impossible. I try to set the Suffix Metadata by batching over Layout items but Layout items are not properly set when the batching is done. The batching is done when msbuild parse my property files, it does not wait for Layout to be declared.
Nevertheless, like MadGnome pointed out, I can batch over LayoutFolder (which is the source items for my includes) because MSBuild does wait for it to be declared.