【问题标题】:WIX util:xmlfile File name is Source attributeWIX util:xmlfile 文件名是 Source 属性
【发布时间】:2013-11-16 19:01:21
【问题描述】:

我正在从 Wise Installer 迁移到 WIX,并且正在使用 util:xmlfile 来更新配置 xml 文件。

这行得通。

<Component Id="config" Guid="*">
  <File Id="config" Source="..\Source\Desktop\prodconfig.xml" KeyPath="yes" Vital="yes" />
    <util:XmlFile 
      Id="_PORT_" File="[INSTALLDIR]prodconfig.xml"  
      Action="setValue" 
      Name="Port" Value="[PORT]" 
      ElementPath="//Configuration/CommConnectionPools/CommConnectionPool" 
      Sequence='1' />
  </File>
</Component>

这不起作用。

<Component Id="config" Guid="*">
  <File Id="config" Source="..\Source\Desktop\prod-config.xml" KeyPath="yes" Vital="yes" />
    <util:XmlFile 
      Id="_PORT_" File="[INSTALLDIR]prod-config.xml"  
      Action="setValue" 
      Name="Port" Value="[PORT]" 
      ElementPath="//Configuration/CommConnectionPools/CommConnectionPool" 
      Sequence='1' />
  </File>
</Component>

当 .msi 与第一个组件一起执行时,一切都很好。第二个版本返回错误“Error 25531. Failed to open XML file...”

据我所知,唯一的区别是文件名中的连字符。

有什么不同的建议吗?

【问题讨论】:

标签: xml wix


【解决方案1】:

尝试使用组件的 id 而不是硬编码名称

[#config] //which will refer to the File Id

而不是

[INSTALLDIR]prod-config.xml

【讨论】:

  • 做到了!我知道说“谢谢”的 cmets 不应该被写出来,但我不会认为这是区别所以......谢谢一百万。这是有道理的,因为 ID 中不允许使用连字符。
  • 克里斯,在您的回答中,您交替声明 File 属性应使用组件的 ID 和文件的 ID。组件的 Id 没有,但文件的 Id 有。
【解决方案2】:

util:XmlFile 标记的File 属性值应参考File 标记的Id 属性。

在你的情况下,这将是

<Component Id="config" Guid="*">
  <File Id="config" Source="..\Source\Desktop\prod-config.xml" KeyPath="yes" Vital="yes" />
    <util:XmlFile 
      Id="_PORT_" File="[#config]"  
      Action="setValue" 
      Name="Port" Value="[PORT]" 
      ElementPath="//Configuration/CommConnectionPools/CommConnectionPool" 
      Sequence='1' />
  </File>
</Component>

在您的示例中,因为您对 Component 标记和 File 标记使用相同的标识符,所以没关系。但一般情况下,File 标签需要使用 Id。

澄清一下,如果您的示例分别使用 configFileComponentFile 标识符。如下所示:

<Component Id="configComponent" Guid="*">
  <File Id="configFile" Source="..\Source\Desktop\prod-config.xml" />
    <util:XmlFile 
      Id="_PORT_" File="[#configFile]"  
[snip]
     />
  </File>
</Component>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-04-02
    • 1970-01-01
    • 1970-01-01
    • 2018-05-15
    • 2017-05-04
    • 1970-01-01
    • 2023-01-20
    • 1970-01-01
    相关资源
    最近更新 更多