4

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?

Tomas Aschan
  • 58,548
  • 56
  • 243
  • 402
  • One of the firsts duplicates: http://stackoverflow.com/questions/11345/xpaths-and-default-namespaces . It was found through http://www.google.com/search?q=site%3Astackoverflow.com+xpath+default+namespace –  Mar 04 '11 at 21:56

3 Answers3

2

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.

Scott
  • 106
  • 2
1

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

joshua.ewer
  • 3,944
  • 3
  • 25
  • 35
1

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!

Martin Buberl
  • 45,844
  • 25
  • 100
  • 144
  • Where do you find NuGetPack task? I have installed Latest Nightly Build from http://msbuildtasks.tigris.org/ and there is no NuGetPack task. I get error that NuGetPack is not defined. – Tomas Feb 10 '12 at 10:03
  • Did you import the Community Tasks target file in your MSBuild script? You can also get an idea on how I did it here: https://github.com/martinbuberl/NUnitHelpers/blob/master/src/NUnitHelpers.msbuild – Martin Buberl Feb 10 '12 at 19:14
  • When I do this the NuGetPack task runs TWICE for some reason. During the second run all the path information is lost which causes it to error out. Any ideas why this is happening? – James Dec 26 '12 at 22:47
  • @James Sorry, I'm not sure why it would run twice for you. – Martin Buberl Dec 27 '12 at 00:10