【问题标题】:In Wix, why can I not get XmlConfig, uninstall, delete to work?在 Wix 中,为什么我不能让 XmlConfig、卸载、删除工作?
【发布时间】:2013-07-10 14:18:07
【问题描述】:

我需要在卸载时从现有配置文件中删除元素。这是相关的 Wix:

<Component Id="Dynamics.exe.config" DiskId="1" Permanent="yes">
    <File Id="AppConfig" Name="Dynamics.exe.config" Source="$(var.ProgramFilesDir)\Microsoft Dynamics\GP2010\Dynamics.exe.config" KeyPath="yes" />
    <util:XmlConfig
                          Id="AppSettings"
                          Action="create"
                          ElementPath="//configuration"
                          Name="appSettings"
                          File="[#AppConfig]"
                          Sequence="1"
                          VerifyPath="appSettings"
                          Node="element"
                          On="install"/>

    <util:XmlConfig
                          Id="AppSettings1"
                          Action="create"
                          ElementPath="//configuration/appSettings"
                          Name="add"
                          File="[#AppConfig]"
                          Sequence="2"
                          VerifyPath="add[\[]@key='AppName'[\]]"
                          Node="element"
                          On="install"/>
    <util:XmlConfig
                          Id="AppSettingsKey1"
                          ElementPath="AppSettings1"
                          Name="key"
                          Value="AppName"
                          File="[#AppConfig]"
                          Sequence="3" />
    <util:XmlConfig
                          Id="AppSettingsValue1"
                          ElementPath="AppSettings1"
                          Name="value"
                          Value="MyApp"
                          File="[#AppConfig]"
                          Sequence="4" />
    <util:XmlConfig
                          Id="AppSettingsRemove1"
                          Action="delete"
                          ElementPath="//configuration/appSettings"
                          File="[#AppConfig]"
                          Sequence="2"
                          VerifyPath="add[\[]@key='AppName'[\]]"
                          Node="element"
                          On="uninstall"/>

创建动作运行。但是,删除/卸载操作不会运行。它不会修改文件。似乎在卸载过程中跳过了该文件。

【问题讨论】:

    标签: wix wix3 wix3.6


    【解决方案1】:

    您已将组件 Permanent 属性配置为 Yes。这样,在卸载过程中将保留更改。

    尝试设置为false。


    我已经测试了以下代码,它符合您的要求。
    可以找到完整的测试代码here

    <Fragment>
    <ComponentGroup Id="ProductComponents"
                    Directory="INSTALLFOLDER">
      <Component Id="CMP_ConfigFile"
                 Guid="{24D22D04-1A98-40D1-83EC-87E68A87A07C}"
                 Permanent="yes"
                 KeyPath="yes"
                 NeverOverwrite="yes">
        <File Id="ConfigFile"
              src="administration.config"></File>
      </Component>
      <Component Id="CMP_XMLConfigInstallChange"
                 Guid="{B1B3B46A-0606-44F4-AEB6-58C5019F5C82}"
                 KeyPath="yes">
        <util:XmlConfig Id="Add_ElementTest"
                        File="[#ConfigFile]"
                        ElementPath="/configuration/configSections"
                        Action="create"
                        Name="section"
                        Node="element"
                        On="install"
                        Sequence="5000">
          <util:XmlConfig Id="Name_Test"
                          File="[#ConfigFile]"
                          ElementId="Add_ElementTest"
                          Name="name"
                          Value="TEST"></util:XmlConfig>
        </util:XmlConfig>
    
      </Component>
    
      <Component Id="CMP_XMLConfig_UninstallChange"
                 Guid="{E1A01B17-247E-4717-8DC0-A923A8E90BE4}"
                 KeyPath="yes">
        <util:XmlConfig Id="Remove_ElementTest"
                        File="[#ConfigFile]"
                        ElementPath="/configuration/configSections"
                        VerifyPath="/configuration/configSections/section[\[]@name='TEST'[\]]"
                        Action="delete"
                        Node="element"
                        On="uninstall"
                        Sequence="5000">
        </util:XmlConfig>
    
      </Component>
    </ComponentGroup>
    

    【讨论】:

    • 是说我应该将我拥有 Permanent="yes" 的位置更改为 Permanent="false" 吗?在卸载期间不会删除文件吗?
    • 也许我误解了你的问题。您想在卸载期间回滚安装更改,还是只想在卸载期间进行一些安装未完成的更改?
    • 在卸载期间,我想使用“删除”操作的元素回滚更改。我无法触发这些动作。我不希望文件被删除。总而言之,在安装时会创建 AppSetting 元素,然后在卸载时需要删除这些元素。但是,该文件必须保留在磁盘上。
    • 对于任何因为“请尝试上面的代码”而感到困惑的人不是一个很好的解释,这里的技巧是使xml转换分开,永久=“无”组件。希望这对未来的访客有所帮助。
    猜你喜欢
    • 2011-11-23
    • 1970-01-01
    • 1970-01-01
    • 2011-05-08
    • 2018-03-27
    • 2015-03-27
    • 2010-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多