XmlUpdate task not to update my xml file

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 should update the empty version node in the 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 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 that the XPath /package/metadata/version pointer points to the right node (because if I changed it to something else, it complains that it will not find the node), but the output says 0 node(s) selected for update.

What am I missing?

+4
source share
3 answers

You may need to include the namespace in the 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 the namespace.

+2
source

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 NuGet tasks (at least for now) are only available in Nightly Build )

Adding a version number to your NuGet package through MSBuild using this task will then look something like this: 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 this helps!

+1
source

Your task should 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 any derogatory term that you would like to use :-)

+1
source

Source: https://habr.com/ru/post/1342061/


All Articles