2014-03-31 61 views
2

我有XML文件,該文件包含一個內容:如何修改與WiX的工具集XML文件

<!--<appcache appCacheType="None" />--> 
<appcache appCacheType="SingleClient" defaultExpiration="3600"/> 

在安裝補丁,我需要改變在XML文件中對此內容:

<appcache appCacheType="None" /> 
    <!--<appcache appCacheType="SingleClient" defaultExpiration="3600"/>--> 

什麼是一個更好的方法來做到這一點?

謝謝。

+0

也許xsl文件? – Gilad

回答

2

我試過(invane)使用MSI Community Extensions來達到這個目的,但是無法讓它們正常運行。 我最終使用了Util-extension中的util:XmlFile -tag,它完美地工作。

  • 使用util擴展的命名空間添加到您的源文件中的Wix - 元素:

    xmlns:util="http://schemas.microsoft.com/wix/UtilExtension" 
    
  • 然後把它作爲一個相關組件的子元素。在你的情況下,你想刪除一個屬性並改變另一個屬性的值。下面的方法可以做到這一點,只需調整ElementPath中的XPath屬性爲與您的標籤匹配的XPath(在示例中,它將更新appcache -tag,該標籤的屬性appCacheType的值爲SingleClient),並且XML-文件:

<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 
    

如果您只想在例如修補,然後爲該組件添加適當的條件。

+0

不能投票,因爲你的第二點是如此模糊。我想你會給出一個具體的代碼示例,因爲你用冒號結束了你的句子,但它不在那裏! – erict

+0

不知何故,這個代碼示例被吞噬了,並沒有顯示,儘管在那裏。爲block-comment添加了'language'-tag,並且它再次出現。謝謝你指點我。 – taffit

+0

很酷,謝謝。這是一個很好的例子 – erict