0

I have a C# application that currently stores user settings/configurations in a separate xml file. My application uses a wix installer and id like to know if there is a way to preserve the xml file should the user be installing a newer version of the application if they install without first removing the older version. The xml file is stored in the CommonAppData folder and should be removed if the application is uninstalled.

Backup question - Is there a better way of doing this than my current method?

UPDATE

I have implemented the following code:

    <CustomAction Id="Cleanup_Files" Directory="CompanyFolder" ExeCommand="cmd /C RD 
        &quot;[CommonFolder]&quot; /s /q" Execute="deferred" Return="ignore" HideTarget="no" 
       Impersonate="no" />
    <InstallExecuteSequence>
      <Custom Action="Cleanup_Files" Before="RemoveFiles" >
        Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE
      </Custom>
    </InstallExecuteSequence>

This removes the CommonFolder directory as required on uninstall but it still removes the directory when upgrading. What changes are necessary to achieve this?

jhorwood28
  • 19
  • 6

2 Answers2

0

The easiest thing to do is: do not insatall this XML file by the setup, but instead let it create by the application if it is not there. By this, an update will not touch the file. With this scenario it is also possible to migrate the settings from an older (or newer) version.

However, the file will also remain on uninstall. If it is a requirement to remove it in this case, you can do this by a custom action with a condition like Installed AND REMOVE="ALL" AND NOT UPGRADINGPRODUCTCODE

Klaus Gütter
  • 11,151
  • 6
  • 31
  • 36
  • Thanks for your reply, I have not used custom actions before. How do i structure the custom action and where do I place it within the product.wxs file? – jhorwood28 Nov 19 '18 at 16:23
  • A very simple approach is in this answer: https://stackoverflow.com/a/17513551/2142950. Smarter solutions require some C# coding, – Klaus Gütter Nov 19 '18 at 17:05
  • Hi Klaus, thank you for your advice im still having trouble getting it to keep the files in place during an upgrade (please see my update) – jhorwood28 Nov 20 '18 at 10:24
  • You can find the installer logs in the %temp% directory. In the log file of the old product being unsinstalled during the update, what is the value of UPGRADINGPRODUCTCODE? – Klaus Gütter Nov 20 '18 at 11:00
0

The solution for me was to follow the advice of Klaus but with some additional changes to my product.wxs file. I had to add 'AllowSameVersionUpgrades="yes"' to the MajorUpgrade section.

    <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of 
    [ProductName] is already installed." />

Thanks to Klaus for all of their advice!

jhorwood28
  • 19
  • 6