How can I keep my config file on a MajorUpgrade?

十年热恋 提交于 2019-12-13 19:45:00

问题


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.

The Product Element:

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

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

The Upgrade Tags:

<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" />

Here is the config file:

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

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: 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.

UPDATE:

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>

回答1:


What's happening during your Major Upgrade:

  1. The CostInitialize/CostFinalize actions determine what components in the new MSI should install. The ConfigComponent decides 'not' to install because it's marked as NeverOverwrite="yes".
  2. The old MSI is removed during the RemoveExistingProducts action. The previous config file is removed.
  3. The new MSI is installed. The ConfigComponent does not get installed based on the check from step 1.

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

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.

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.



来源:https://stackoverflow.com/questions/36405678/how-can-i-keep-my-config-file-on-a-majorupgrade

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!