XmlUpdate task not updating my XML file

允我心安 提交于 2021-02-19 03:19:59

问题


I have the following task in an MSBuild script:

<XmlUpdate
    Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
    XmlFileName="$(PackageDir)\temp\OddEnds.Testing\OddEnds.Testing.nuspec"
    XPath="/package/metadata/version"
    Value="%(OddEndsTestingAsmInfo.Version)" />

which is supposed to update an empty version node in a NuGet specification file with the assembly version. My .nuspec file looks like this:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http:www.w3.org/2001/XMLSchema-instance">
    <metadata xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
        <id>OddEnds</id>
        <authors>Tomas Lycken</authors>

        <!-- Here's the node I want to update -->
        <version></version>

        <owners>Tomas Lycken</owners>
        <description>Odd ends and bits that I might need in any project.</description>
    </metadata>
</package>

I believe the XPath pointer /package/metadata/version points to the right node (since if I change it to something else, it complains about not finding the node) yet the output says 0 node(s) selected for update.

What am I missing?


回答1:


You may need to include the namespace in your xpath string.

Check out this blog post: http://www.lesnikowski.com/blog/index.php/update-nuspec-version-from-msbuild/

You can also try //*:version. This will select all version elements regardless of namespace.




回答2:


I had exactly the same problem with NuGet, XmlUpdate, MSBuild and XPath.

In the end I switched to the NuGetPack task of the MSBuild Community Tasks project.
(Note that the NuGet tasks are (at least for right now) only available in the Nightly Build)

Adding the version number to your NuGet package via MSBuild using this task would then look somehow like the following snippet:

<Target Name="NuGet">
  <GetAssemblyIdentity AssemblyFiles="$(BuildCompileDirectory)\$(AssemblyName).dll">
     <Output TaskParameter="Assemblies" ItemName="AssemblyIdentities"/>
  </GetAssemblyIdentity>

  <NuGetPack
    ToolPath="$(ToolsDirectory)"
    WorkingDirectory="$(BuildCompileDirectory)"
    File="$(SrcDirectory)\$(SolutionName).nuspec"
    Version="%(AssemblyIdentities.Version)"/>
</Target>

Hope that helps!




回答3:


Your task would need to look like this:

<XmlUpdate
    Prefix="xmlsucks"
    Namespace="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd"
    XmlFileName="$(PackageDir)\temp\OddEnds.Testing\OddEnds.Testing.nuspec"
    XPath="/xmlsucks:package/xmlsucks:metadata/xmlsucks:version"
    Value="%(OddEndsTestingAsmInfo.Version)" />

Feel free to change the prefix to whatever derogatory term you would like to use :-)



来源:https://stackoverflow.com/questions/5175160/xmlupdate-task-not-updating-my-xml-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!