1

I am trying to alter a string in the batch. Replacing a string works great outside the scope of batching.

In my example I am trying to replace part of the directory.

    <?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Build">
     <PropertyGroup>
        <SourcePath>C:\LocTest</SourcePath>
     </PropertyGroup>
    <ItemGroup>
      <RelBinfolder Include="$(SourcePath)\one\**\*;$(SourcePath)\tweo\**\*;$(SourcePath)\three\**\*">
      </RelBinfolder>
    </ItemGroup>
    <Message Text="Directory: %(RelBinfolder.Directory)" />
    <Message Text="Batching does not work: %(RelBinfolder.Directory.Replace('LocTest', 'SomethingNew'))" />
    <Message Text="This works fine: $(SourcePath.Replace('LocTest', 'SomethingNew'))" />
    </Target>
</Project>

Thank you

  • Very confusing syntax. I tried that one but they are attempting to solve a slightly different problem and more of the solution is not present for me to understand how that works. This does not work. Causes errors from msbuild –  Nov 18 '16 at 04:45
  • Did you try the line I posted in my comment? I'm fairly sure that works. – stijn Nov 18 '16 at 10:26

1 Answers1

0

The best answer was a tip here https://stackoverflow.com/a/27865918/6840349

All other syntax did not seem to work. Here is my working example for those that might follow later:

<Message Text="Adapted: $([System.String]::Copy('%(RelBinfolder.RecursiveDir)').Replace('tweo', 'two'))" />

Thank you!

Community
  • 1
  • 1