Filip
Filip

Reputation: 3347

XmlPoke task trims value

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)?

Upvotes: 9

Views: 352

Answers (1)

Simon Mourier
Simon Mourier

Reputation: 138776

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" ... />

Upvotes: 6

Related Questions