开发者

XmlUpdate task not updating my XML file

I have the following task in an MSBuild script:

<XmlUpdate
    Namespace="htt开发者_运维问答p://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?


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.


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!


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜