我有包含以下内容的 XML 文件:
<!--<appcache appCacheType="None" />-->
<appcache appCacheType="SingleClient" defaultExpiration="3600"/>
在安装补丁时,我需要将 XML 文件中的内容更改为:
<appcache appCacheType="None" />
<!--<appcache appCacheType="SingleClient" defaultExpiration="3600"/>-->
有什么更好的方法吗?
谢谢。
最佳答案
我尝试(徒劳地)使用 MSI Community Extensions为此目的,但无法让它们启动并运行。
我最终使用了 Util 扩展中的 util:XmlFile
标签,该标签运行完美。
将 Util 扩展的命名空间添加到
Wix
元素中的源文件中:xmlns:util="http://schemas.microsoft.com/wix/UtilExtension"
然后将其用作相关组件的子元素。在您的情况下,您想要删除一个属性并更改另一个属性的值。下面的代码应该可以解决问题,只需将
ElementPath
属性中的 XPath 调整为与您的标记匹配的属性即可(在示例中,它更新了appcache
标记,该标记具有属性appCacheType
,值为SingleClient
)和 XML 文件的 filekey:
<Component Id="myComponentToUpdateTheXmlFile" ... >
<!-- Removing the defaultExpiration-attribute first -->
<util:XmlFile Id="UpdateAppCacheTag" Action="deleteValue" ElementPath="//appcache[\[]@appCacheType='SingleClient'[\]]/@defaultExpiration" File="[#MyConfigFile.xml]" SelectionLanguage="XPath" Sequence="1" Name="defaultExpiration" />
<!-- Now updating the value -->
<util:XmlFile Id="UpdateAppCacheTag" Action="setValue" ElementPath="//appcache[\[]@appCacheType='SingleClient'[\]]/@appCacheType" File="[#MyConfigFile.xml]" SelectionLanguage="XPath" Sequence="2" Value="None" />
</Component>
调用蜡烛和灯光时,请务必在命令行上添加 Util 扩展:
<candle or light command line> ... <parameters> ... -ext <PathToWiXExtensions>\WixUtilExtension.dll
如果您只想在例如修补,然后为此组件添加适当的条件。
关于wix - 如何使用wix工具集修改XML文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22759769/