如何在 MajorUpgrade 上保留我的配置文件? [英] How can I keep my config file on a MajorUpgrade?

查看:20
本文介绍了如何在 MajorUpgrade 上保留我的配置文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们使用 wix 3.9 为我们的产品创建 msi.我们的目标:我们想通过 msi 提供一个配置文件(.txt 文件).如果安装文件夹中已存在配置文件,则升级不应覆盖该文件.不幸的是,在升级时,Wix 删除了配置文件.

We use the wix 3.9 to create an msi for our product. Our Target: We want to deliver a config file (.txt-file) via the msi. When an config file already exists in the installation folder, the file should not be overwritten by an upgrade. Unfortunately, on an upgrade, Wix removes the configuration file.

产品元素:

<Product Id="*" Name="$(var.AppName) V$(var.Version) $(var.TargetBuild)" Language="1033" Version="$(var.Version)" Manufacturer="$(var.Manufacturer)" UpgradeCode="$(var.UpgradeCode)">

$(var.UpgradeCode) 是静态的,永远不会改变.

The $(var.UpgradeCode) is static and will never be changed.

升级标签:

<MajorUpgrade DowngradeErrorMessage="A newer version of $(var.AppName) is already installed." AllowSameVersionUpgrades="yes" />

<Upgrade Id="$(var.UpgradeCode)">
  <UpgradeVersion Minimum="1.0.0"
                  IncludeMinimum="yes"
                  OnlyDetect="yes"
                  Maximum="$(var.Version)"
                  IncludeMaximum="yes" 
                  Property="PREVIOUSVERSIONSINSTALLED" />
</Upgrade>

<Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />

这是配置文件:

<Component Id="ConfigComponent" NeverOverwrite="yes" Guid="GUID-HERE">
    <File Id="ConfigOutput" KeyPath="yes" Name="MyConfig.config" Source="MyConfig.config.bak"/>
</Component>

此外,我使用 RemoveFolderEx 来删除应用程序本身生成的文件.但是当我注释掉这个块时,问题仍然出现.但我想显示代码块的完整性:

In Addition, I use RemoveFolderEx to remove generated files by the Application itself. But when I commented out this block, the problem still occurs. But I want to show the codeblock for the completeness:

<Component Id="RemoveAll" Guid="MYGUID">
    <RemoveFile Id="RemoveAllFilesOnUninstall" Directory="APPLICATIONFOLDER" Name="*.*" On="uninstall" />
    <RemoveFolder Id="RemoveAllFoldersOnUninstall" Directory="APPLICATIONFOLDER" On="uninstall" />

    <RegistryValue Root="HKLM" Key="SOFTWARE\$(var.Manufacturer)\$(var.AppName)" Name="Path" Type="string" Value="[APPLICATIONFOLDER]" KeyPath="yes" />
    <util:RemoveFolderEx On="uninstall" Property="APPLICATIONFOLDER" /> 
</Component>

Repro: 首先,我们安装软件,并且文件MyConfig.config"按预期出现在应用程序文件夹中.之后,我们在此配置文件中进行更改.接下来,我们构建第二个 .msi 并执行它.进行更新后,所有文件都会按预期覆盖.但是我们现在在安装文件夹中缺少文件MyConfig.config".

Repro: At first, we install the Software and the file 'MyConfig.config' appears in the application folder as expected. After that, we make changes inside of this config file. At next, we build a second .msi and execute it. When the update is made, all files are overwritten as expected. But we are missing the file 'MyConfig.config' in the installation folder now.

更新:

属性 Permanent="yes" 也没有按预期工作.升级时仍会删除配置文件:

The attribute Permanent="yes" does also not work as expected. The config File is still removed on an upgrade:

<Component Id="ConfigComponent" Permanent="yes" NeverOverwrite="yes" Guid="GUID-HERE">
    <File Id="ConfigOutput" KeyPath="yes" Name="MyConfig.config" Source="MyConfig.config.bak"/>
</Component>

推荐答案

主要升级期间发生的事情:

What's happening during your Major Upgrade:

  1. CostInitialize/CostFinalize 操作确定应安装新 MSI 中的哪些组件.ConfigComponent 决定不"安装,因为它被标记为 NeverOverwrite="yes".
  2. 旧 MSI 在 RemoveExistingProducts 操作期间被删除.之前的配置文件被删除.
  3. 安装了新的 MSI.根据步骤 1 中的检查,未安装 ConfigComponent.

一个快速的解决方案(尽管我确信有更好的方法):

A quick solution (although I'm sure there are better approaches out there):

接下来,将您的 ConfigComponent 标记为 Permanent="yes",以便 MSI 永远不会删除它.您需要添加一个删除文件的自定义操作,并将其设置为$ConfigComponent=2 And Not UPGRADINGPRODUCTCODE",以便它仅在通过修改或完全卸载将组件设置为删除时执行,但不执行升级.

Going forward, mark your ConfigComponent with Permanent="yes" so that MSI never removes it. You'll need to add a custom action that removes the file, and condition it on "$ConfigComponent=2 And Not UPGRADINGPRODUCTCODE" so that it only executes when the component is set to be deleted through a modify or full-uninstall, but not an upgrade.

如果您的 MSI 已经交付给全世界,并且您需要修复升级方案,您将需要编写一个自定义操作,在旧的 MSI 将其删除之前将配置文件复制到备份位置.然后另一个自定义操作将配置文件复制回正确的目录.

If your MSI is already shipped to the world and you need to fix the upgrade scenario you'll need to write a custom action that copies the config file to a backup location before the old MSI removes it. Then another custom action to copy the config file back into the correct directory.

这篇关于如何在 MajorUpgrade 上保留我的配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆