Question

I am trying to set a property value based on Item But property doesn't seem to notice Item For example, my code is like

<ItemGroup>
   <temp Include="test.txt"></temp>
</ItemGroup>

<PropertyGroup>
  <Name>%(temp.Identity)</Name>
  <Test>$([system.IO.File]::ReadAllText('$(Name)').Replace('ABC', '###'))</Test> 
</PropertyGroup>    

<Target Name="Write">
   <Message Text="$(Name)"/>
   <WriteLinesToFile File="%(temp.Filename).asl" Lines="$(Test)" Overwrite="true"/> 
</Target>

But when I run that, it says it cannot read %(temp.Identity) Am I missing anything?? Thank you!

Was it helpful?

Solution

Properties are evaluated before any items. Move the group into a target for delayed evaluation, your "Write" or a generic InitialTargets one.

See Property and Item Evaluation Order.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top