Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 722
Filip Avatar asked Dec 04 '18 13:12

Filip


1 Answers

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" ... />
like image 127
Simon Mourier Avatar answered Oct 17 '22 23:10

Simon Mourier