简体   繁体   English

XmlUpdate任务不更新我的XML文件

[英]XmlUpdate task not updating my XML file

I have the following task in an MSBuild script: 我在MSBuild脚本中有以下任务:

<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. 应该使用程序集版本更新NuGet规范文件中的空version节点。 My .nuspec file looks like this: 我的.nuspec文件如下所示:

<?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. 我相信XPath指针/package/metadata/version指向正确的节点(因为如果我将其更改为其他东西,它抱怨没有找到节点)但输出表示0 node(s) selected for update.

What am I missing? 我错过了什么?

You may need to include the namespace in your xpath string. 您可能需要在xpath字符串中包含命名空间。

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

You can also try //*:version. 您也可以尝试// *:version。 This will select all version elements regardless of namespace. 这将选择所有版本元素,而不管命名空间。

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 :-) 随意将前缀更改为您想要使用的任何贬义词:-)

I had exactly the same problem with NuGet, XmlUpdate, MSBuild and XPath. 我与NuGet,XmlUpdate,MSBuild和XPath有完全相同的问题。

In the end I switched to the NuGetPack task of the MSBuild Community Tasks project. 最后,我切换到了MSBuild社区任务项目的NuGetPack任务。
(Note that the NuGet tasks are (at least for right now) only available in the Nightly Build ) (请注意,NuGet任务(至少目前为止)仅在Nightly Build中可用)

Adding the version number to your NuGet package via MSBuild using this task would then look somehow like the following snippet: 使用此任务通过MSBuild将版本号添加到NuGet包中,看起来就像下面的代码片段:

<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! 希望有所帮助!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM