2

When uninstalling my application, I'd like to configure the Wix setup to NOT to remove few files that were added as part of the installation. It seems like the uninstaller removes all the files that were originally installed from the MSI file. How do I do that?

Here are my files which I wish to keep it forever

<Binary Id="RootCABinary" SourceFile="Assets\Certificates\RootCA.cer" />
<Binary Id="SubCABinary" SourceFile="Assets\Certificates\SubCA.cer" />

I have used WixIIsExtension.dll to install these certificates to the windows store.

Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66
kudlatiger
  • 3,028
  • 8
  • 48
  • 98

2 Answers2

2

Overwrite: Is it important that the file never gets overwritten? If so, add "Never Overwrite" to your component. WiX attribute: NeverOverwrite="yes". Remember to test upgrade scenarios!


Permanent Component: As stated by Pavel, you can set a component permanent:

<Component Permanent="yes">
    <File Source="License.rtf" />
</Component>

Blank GUID: Another way to do it is to set a blank component GUID. It essentially means "install and then leave alone". No repair or uninstall should be done (remember to add NeverOverwrite="yes" if the file should never be overwritten):

<Component Guid="" Feature="MainApplication">
    <File Source="SubCA.cer" KeyPath="yes" />
</Component>

Read-Only Copy: I sometimes install files to a per-machine path (for example somewhere under program files) and then copy them to a per-user location (somewhere in the user-profile) on application launch, and then do operations on them that entail that the files should not be deleted. This is good in cases where you want to do something that change the files in question (they need to be writable). Then it is good to "untangle" them from deployment concerns (files will not be meddled with by installer operations at all - the installer has no knowledge of them). The original read-only copy installed to program files can be uninstalled though (no longer needed?).


Other approaches: You can also create such files using custom actions during installation (usually text files only), you can download the file in question from your web site on application launch (makes the file easy to manage and update / replace? Vulnerable to connection problems - firewalls, etc...) and the application can create the file using "internal defaults" in the main executable on launch. And there are no doubt further approaches that I can't recall.

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • Another approach, that doesn't require any special WiX authoring: Install the file regularly. Let the program modify the "Last Modification" date of the file to be later than the "Creation" date (which happens regularly if the program actually modifies the file). This works, because one of the rules of MSI is to never delete "user modified files" which are detected by comparing creation date and modification date. If they differ, the file is assumed to be modified by the user. Though I think this works for unversioned files only. – zett42 Apr 08 '19 at 11:30
  • Yes, overwrite will be prevented, but not "revert" as in the file is uninstalled and then re-installed making it appear overwritten? (for early RemoveExistingProducts major upgrades where all files are removed / uninstalled before they are reinstalled). – Stein Åsmul Apr 08 '19 at 12:09
  • I do not see logs of the certificate copy event! Anything I have to explicitly enable? – kudlatiger Apr 09 '19 at 04:45
  • "_as in the file is uninstalled and then re-installed_" -- MSI will neither uninstall nor overwrite an unversioned file that is modified. Maybe I don't understand what you are trying to say. – zett42 Apr 09 '19 at 09:20
  • I didn't see that you have defined these as `Binary elements`. You use those to add to the binary table for use in custom actions, and to use the [`Certificate element`](http://wixtoolset.org/documentation/manual/v3/xsd/iis/certificate.html) which is strangely in the IIS namespace (I have never used this feature). Please try to set the component permanent. That should prevent uninstallation. You can also install the certificates as [`File elements`](http://wixtoolset.org/documentation/manual/v3/xsd/wix/file.html), but then you need a custom action to install them into the store (I presume). – Stein Åsmul Apr 09 '19 at 10:15
1

Put your binaries in a separate WiX component and make it permanent. Have a look at this thread as well

Pavel Anikhouski
  • 21,776
  • 12
  • 51
  • 66