문제

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

도움이 되었습니까?

해결책

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>
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top