9

Is there a way to use value ending with space as XmlPoke value? When I execute task, value is replaced but without space at the end.

Reproduction:

test.targets:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <Target Name="Build">
        <Copy SourceFiles="test.xml" DestinationFiles="output.xml"/>
        <XmlPoke Query="/root/element/@attr[.='replaceme']|/root/replaceme" Value="X " XmlInputPath="output.xml"/>
    </Target>
</Project>

test.xml:

<root>
    <element attr="replaceme" />
    <replaceme/>
</root>

When I run:

MSBuild /v:detailed test.targets

I get output.xml without space:

<root>
  <element attr="X" />
  <replaceme>X</replaceme>
</root>

Is there a way to force XmlPoke to set correct value (with space at the end)?

Filip
  • 3,257
  • 2
  • 22
  • 38

1 Answers1

6

Value is an MSBuild "Item" Usually, items represent file paths and MSBuild treats these in a special (undercover) way.

So, the issue is not related to XML escaping but to MSBuild item escaping. This is how you can force the space character:

<XmlPoke ... Value="X%20" ... />
Simon Mourier
  • 132,049
  • 21
  • 248
  • 298
  • Good find. I was reading up on one of the supporting inks was wondering if by *undercover* you meant that it works but they make no mention of it? Didn't see it in the table here https://learn.microsoft.com/en-us/visualstudio/msbuild/msbuild-special-characters?view=vs-2017 – Nkosi Dec 09 '18 at 11:57
  • @Nkosi - what I mean is many msbuild attributes are not really raw strings: https://github.com/Microsoft/msbuild/blob/880d215472e5e2a8d75352f753c8b97b6c2e3a54/src/Utilities/TaskItem.cs#L158 – Simon Mourier Dec 09 '18 at 12:10