Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Wix CopyFile before uninstall and restore after uninstalltion

Tags:

wix

I am performing major upgrade and uninstalling existing product before installing new version. But I want to retain the existing config file.

As the earlier version didnt had Permanent="yes" , it removes the config file on uninstallation.

And How can I do something like this make a copy of 'app.config' as 'app.config.bak' before uninstalltion. After uninstalltion revert 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

like image 961
Ankit Sharma Avatar asked Jun 20 '13 21:06

Ankit Sharma


1 Answers

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

It is simply a timing issue that you are having. You are telling all three actions to take place after InstallInitialize so it is very possible that they are not staying in the order that they are written. It is always a better idea to explicitly list which order you want them in. A better, complete fix, would be:

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

EDIT: (Based on comments) To create a custom action in the MSI you will need to make a CustomAction element. The code behind for creating a custom action is also needed. However, if you are only trying to copy a file I would suggest using the CopyFile element. It is much much easier and cleaner than going through all the custom action steps to do what I think you are going for.

like image 185
Christopher B. Adkins Avatar answered Jan 02 '23 06:01

Christopher B. Adkins