Ehud Grand
Ehud Grand

Reputation: 3703

Wix installer major upgrade custom action before removing old version

I'm using wix installer (version 3), I have an msi of version 1.99 and another msi of version 2.00. My app has the ability to do import and export of the DB by calling it with some arguments. I'm trying to perform a major upgrade, and trying to call custom actions before and after the upgrade. Now, the custom action code works just fine. The problem is, that the code that should run BEFORE the old version is removed, is running AFTER it is removed, and thus cannot activate the app and produce the backup files.

In short: How do I time the custom actions to do their work before the removal of the old version?

This is how I call them:

    <CustomAction Id="doExport"
              Return="check"
              Execute="immediate"
              BinaryKey="ImportExportBinary"
              DllEntry="BeforeInstall" />

    <CustomAction Id="doImport"
                Return="check"
                Execute="immediate"
                BinaryKey="ImportExportBinary"
                DllEntry="AfterInstall" />

  <InstallExecuteSequence>
     <Custom Action="doExport" Before="InstallInitialize"> NOT Installed</Custom>
     <Custom Action="doImport" After="InstallFinalize"> NOT Installed</Custom>
  </InstallExecuteSequence>

EDIT:

Here is the major upgrade code:

<MajorUpgrade AllowDowngrades="no" 
                Schedule="afterInstallFinalize"
                DowngradeErrorMessage='Cannot downgrade!' 
                AllowSameVersionUpgrades='yes' ></MajorUpgrade>

I've tried playing a bit with "Execute" attribute of the CustomAction element, without any results.

Upvotes: 1

Views: 2138

Answers (2)

Eazael
Eazael

Reputation: 104

I tryied the same thing, and it took me long to find a way for it to work. You can use

<Custom Action="doExport" Before="RemoveExistingProducts"></Custom>

The option RemoveExistingProducts refers to the action of uninstalling the existing version of your product, so you have to execute the action before the existing version is removed.

I did not find this option in this list: https://learn.microsoft.com/en-us/windows/win32/msi/suggested-installexecutesequence

But it seems to work, and executes before the list of options described in the link.

About the options which should go inside the <Custom></Custom> tag, I am not sure, but I hope it helps to start the code at the right moment.

Upvotes: 1

PhilDW
PhilDW

Reputation: 20790

First, do your upgrade creating a verbose log to make sure your custom actions are working and being called. You've marked them immediate, so they run before anything changes on the system and so will be called before the old product is removed. When you say "the code works just fine" you probably mean when you run it from your interactive account. But that's not happening. Your code is running out of an msiexec.exe process, the working directory is not what you expect, your code may not be looking in the right place for the files, it will not be elevated and so may not be able to do what it thinks it can. There are many opportunities for your code to not work as expected.

If you ever marked them as deferred I can see why doExport might not work. Without seeing your MajorUpgrade element I can't be sure, but the default scheduling for RemoveExistingProducts is afterInstallValidate. Your custom action is before InstallInitialize, so the actual sequence in the MSI file could easily be InstallValidate, RemoveExistingProducts, doExport, InstallInitialize.

and RemoveExistingProducts that does the uninstall of the old version is before your custom actions.

So if you want to use execute deferred, try Before="RemoveExistingProducts" on your doExport, or use Schedule in your MajorUpgrade to afterInstallInitialize and keep your doExport before InstallInitialize.

Upvotes: 1

Related Questions