【问题标题】:XPath in MSBuild (SDC) and WIXMSBuild (SDC) 和 WIX 中的 XPath
【发布时间】:2010-11-25 02:34:23
【问题描述】:

新问这个问题->

我有一个需要使用 MSBuild 修改的 WIX 文件。开头是这样的:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
     xmlns:iis="http://schemas.microsoft.com/wix/IIsExtension">

  <?--... Various Removed Params ...-->

  <Product Id='$(var.ProductCode)'
    UpgradeCode='$(var.UpgradeCode)'
    Name='$(var.AppName)' Language="1033" Version='$(var.ProductVersion)'
    Manufacturer='$(var.Manufacturer)'>
    <Package Id='$(var.PackageCode)' InstallerVersion="200" 
    Compressed="yes" />

  <?--... More of the WIX XML file ...-->

  <iis:WebApplication Id='STWebApp' Name='MyWebSite' Isolation='medium' />

  <?--... Rest of the WIX XML file ...-->

我的问题是 SDC 任务似乎无法引用任何与 WIX 相关的 xml 节点。例如:

<XmlFile.SetAttribute Path="$(MSBuildProjectDirectory)\TestProduct.wxs"
         XPath="//iis:WebApplication" Namespaces="@(Namespaces)" 
         Name="Name" Value="$(VersionTag)"/>

工作得很好,因为它不使用任何 Wix 节点(只是一个 iis 节点),但如果我使用它的完整 XPath 路径(/Wix/Product/iis:WebApplication)任务返回: 找不到资源字符串 找不到 XPath 表达式的匹配项

这不是问题,直到我想引用目录节点 (/Wix/Product/Directory/Directory/Directory/Directory[@Id='STWebSiteDir'])

我尝试过使用完整的 XPath 和较短的 //Directory[@Id='STWebSiteDir']。我尝试过单引号和双引号,我尝试将 WIX 命名空间添加到调用中(不带前缀)。

<ItemGroup>
  <Namespaces Include="http://schemas.microsoft.com/wix/IIsExtension">
    <Prefix>iis</Prefix>
    <Uri>http://schemas.microsoft.com/wix/IIsExtension</Uri>
  </Namespaces>
  <Namespaces Include="http://schemas.microsoft.com/wix/2006/wi">
    <Prefix></Prefix>
    <Uri>http://schemas.microsoft.com/wix/2006/wi</Uri>
  </Namespaces>
</ItemGroup>

我什至试图获得对 /Wix/Product 的引用,但还是失败了:

<XmlFile.SetAttribute Path="$(MSBuildProjectDirectory)\TestProduct.wxs" 
            XPath="/Wix/Product" Namespaces="@(Namespaces)" 
            Name="Name" Value="MODIFIED"/>

我显然遗漏了一些东西。任何人都知道去哪里让它工作?

瓦卡诺

【问题讨论】:

  • 如果您的 XPath 引擎是标准的,这是常见问题解答:没有前缀的 QName 测试选择空(或空)命名空间 URI 中的元素,而不是默认命名空间中的元素。因此,您需要注册命名空间 URI 和前缀绑定,并将此前缀添加到您的路径中,即:/wi:Wix/wi:Product

标签: msbuild xpath wix microsoft.sdc.tasks


【解决方案1】:

你能在命令行上给预处理器定义变量吗?

candle -dVariableName=ValueForVariable

这可能会容易得多。

【讨论】:

    【解决方案2】:

    您是否在 @(Namespaces) 中包含了 Wix 默认命名空间?

    【讨论】:

    • 我一定无法理解你,因为我的问题中有 WIx 命名空间!!!!!!
    • 所以你下面的解决方案就是我想说的。默认值与 Empty 不同。
    • 确实如此。而是投票给你。
    【解决方案3】:
    <ItemGroup>
      <Namespaces Include="http://schemas.microsoft.com/wix/IIsExtension">
        <Prefix>iis</Prefix>
        <Uri>http://schemas.microsoft.com/wix/IIsExtension</Uri>
      </Namespaces>
      <Namespaces Include="http://schemas.microsoft.com/wix/2006/wi">
         <Prefix>wis</Prefix>
        <Uri>http://schemas.microsoft.com/wix/2006/wi</Uri>
      </Namespaces>
    </ItemGroup>
    

    你也应该为wi命名空间添加一个前缀,之后就可以了,我已经测试了。

    【讨论】:

      【解决方案4】:

      好的,答案如下:

      wix 部分需要缺少命名空间前缀,而不仅仅是留空

      <ItemGroup>
        <Namespaces Include="http://schemas.microsoft.com/wix/IIsExtension">
          <Prefix>iis</Prefix>
          <Uri>http://schemas.microsoft.com/wix/IIsExtension</Uri>
        </Namespaces>
        <Namespaces Include="http://schemas.microsoft.com/wix/2006/wi">
      
          <Uri>http://schemas.microsoft.com/wix/2006/wi</Uri>
        </Namespaces>
      </ItemGroup>
      

      然后你需要在文件中的 wix 命名空间中添加一个前缀值。我用过 tst。

      瓦卡诺

      【讨论】:

        猜你喜欢
        • 2023-04-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-07
        相关资源
        最近更新 更多