Wix CopyFile before deletion and recovery after deletion

Before installing a new version, I perform a major upgrade and uninstall of an existing product. But I want to save the existing configuration file.

Since the previous version did not have Permanent = "yes", it deletes the configuration file upon removal.

And how can I do something like this, make a copy of "app.config" as "app.config.bak" before uninstalling. After uninstalling, remove it back from 'app.config.bak' to 'app.config'.

<DirectoryRef Id="INSTALLDIR"> <Component Id="BackupConfigComponent" Guid="87368AF7-4BA2-4302-891A-B163ADDB7E9C"> <CopyFile Id="BackupConfigFile" SourceDirectory="INSTALLFOLDER" SourceName="app.config" DestinationDirectory="INSTALLFOLDER" DestinationName="app.config.bak" /> </Component> </DirectoryRef> <DirectoryRef Id="INSTALLDIR"> <Component Id="RestoreConfigComponent" Guid="87368AF7-4BA2-4302-891A-B163ADDB7E9C"> <CopyFile Id="RestoreConfigFile" SourceDirectory="INSTALLFOLDER" SourceName="app.config.bak" DestinationDirectory="INSTALLFOLDER" DestinationName="app.config" /> </Component> </DirectoryRef> <InstallExecuteSequence> <Custom Action="BackupConfigFile" After="InstallInitialize" /> <RemoveExistingProducts After="InstallInitialize" /> <Custom Action="RestoreConfigFile" After="InstallInitialize" /> </InstallExecuteSequence> 

thanks

+6
source share
1 answer

All you have to do is change <Custom Action="RestoreConfigFile" After="InstallInitialize" /> to <Custom Action="RestoreConfigFile" After="RemoveExistingProducts " />

It is just a matter of time that you have. You report all three actions after InstallInitialize, so it is very possible that they do not remain in the order in which they are written. It is always the best idea to explicitly indicate in which order you want them. Best, full fix:

 <Custom Action="BackupConfigFile" After="InstallInitialize" /> <RemoveExistingProducts After="BackupConfigFile" /> <Custom Action="RestoreConfigFile" After="RemoveExistingProducts " /> 

EDIT: (Based on comments) To create a custom action in MSI, you need to create a CustomAction element. You also need code to create a custom action. However, if you are only trying to copy a file, I would suggest using the CopyFile element. This is much simpler and cleaner than going through all the steps of a user action to do what I think you are going to do.

+3
source

Source: https://habr.com/ru/post/947786/


All Articles