5

I'm in the process of upgrading an old Visual Studio setup project installer to a WiX installer.

I have a problem with the new installer though - it keeps removing a config file that was installed with the old installer.

The component in the .wxs file looks like this:

<Component Id="MyConfig" NeverOverwrite="yes" Permanent="yes">
  <File Id="MyApp.exe.config" Name="MyApp.exe.config" />
</Component>

I tried setting the component Id and Guid to the same as they were in the old installer, but then it replaces the existing config file with the new one - which I don't want, as the config file may have been modified since the initial installation.

What I want, is if MyApp.exe.config is already installed it should not be removed or replaced.

Cocowalla
  • 13,822
  • 6
  • 66
  • 112
  • possible duplicate of [How to keep a config file when major upgrade in wix v3.8?](http://stackoverflow.com/questions/16186187/how-to-keep-a-config-file-when-major-upgrade-in-wix-v3-8) – Erti-Chris Eelmaa Dec 15 '13 at 10:16
  • 1
    @Erti-ChrisEelmaa it's *not* a duplicate. In my case it works fine when doing a major upgrade with the WiX installers. My issue is *only* when upgrading an older installer's installation with the WiX installers. – Cocowalla Dec 15 '13 at 11:06

1 Answers1

6

Make sure your RemoveExistingProducts is scheduled after InstallExecute, eg: afterInstallExecute. GUID and Keypath of the component need to be the same as they were in your previous installer. MSI will only overwrite the old config file if it's modified date is equal to its create date. If the modified date is after the create date the config file was modified and MSI will not overwrite. You shouldn't need the Permanent attribute, that makes this file leaked on uninstall. Don't use NeverOverwrite either: per the docs this is only for registry.

TheESJ
  • 2,357
  • 17
  • 13
  • If I schedule RemoveExistingProducts after InstallExecute, then when I run the new installer all of the existing files are deleted and I'm left with nothing but empty folders – Cocowalla Dec 14 '13 at 19:14
  • That's because you aren't ref-counting the existing components when you install the new product. Double check that all your component GUID and keypath are the same for all components that have the same path in both products. – TheESJ Dec 15 '13 at 01:45
  • Not sure what 'ref-counting' means? Do you mean I need to set the GUID and keypath for *all* components in the new installer to the same as they were in the old installer? That sounds *really* painful. – Cocowalla Dec 15 '13 at 11:03
  • You were right - I'd mistakenly set the wrong GUID on the component. After changing it to the same as in the old installer, the config file is no longer being deleted. – Cocowalla Dec 15 '13 at 16:46
  • Yep, MSI is painful. If you install a component to the same path as another installer you need to have the same GUID and keypath for that component. One way to make this easier is to use WIX's star-guids. They'll automatically generate a component GUID based on a stable keypath. It only works for statically determinable paths (eg: program files\...) but that's what most folks use now-a-days. – TheESJ Dec 16 '13 at 05:28
  • that's what I'm doing for the new installer, for almost all components expect the config file. Well, I'm not specifying a GUID at all, which I believe generates it automatically? – Cocowalla Dec 16 '13 at 10:57
  • this is weird, but this only seems to work with my x86 installers; for the x64 variants it still deletes the config file. I've quadruple checked the Guids and Ids are correct - any ideas? – Cocowalla Dec 17 '13 at 17:43
  • with me it works on x64, Wix 3.11 .. I only need to remember the Guid of the appsettings.json, not all of them – Arjan Nov 18 '19 at 13:57