Reputation: 21194
I got the following test code:
<Target Name="TestTarget">
<MSBuild.ExtensionPack.Xml.XmlFile
TaskAction="UpdateElement"
File="@(ConfigurationFile)"
XPath="/MyConfiguration/Settings/RetentionTime"
InnerText="$(RetentionTime)"/>
</Target>
(ConfigurationFile is within an ItemGroup, somewhere else I need the FullName, and so it comes in handy)
The output is: XmlFile: C:\Development\Test\build\Test.xml Update Element: /MyConfiguration/Settings/RetentionTime. InnerText: 30
No errors, build succeeded. However, when I open the XML file afterwards the RetentionTime element is still empty.
If I change the XPath to a non-existing element there is an error, so this should be right. Do you know if I'm missing something? I don't get it...
Upvotes: 0
Views: 1015
Reputation: 446
One pitfall is when the target-file declares a default namespace. This namespace must be provides in the xpath:
<Target Name="TestTarget">
<ItemGroup
<_namespaces Include="MyNamespace">
<Prefix>mns</Prefix>
<Uri>http://myNamespace</Uri>
</_namespaces>
</ItemGroup>
<MSBuild.ExtensionPack.Xml.XmlFile
TaskAction="UpdateElement"
File="@(ConfigurationFile)"
XPath="/mns:MyConfiguration/mns:Settings/mns:RetentionTime"
InnerText="$(RetentionTime)"
Namespaces="@(_namespaces)"/>
</Target>
Upvotes: 2