Search code examples
c#wixwindows-installerupgradecustom-action

How to identify and upgrade current installations?


I'm changing our installer to support the possibility of having several versions of our software installed at the same time.

This leads to the scenario where several earlier versions of our product are installed and I need to let the user choose which of the current versions should be upgraded.

Currently I'm using a property called OLDERFOUND to detect if their are older versions at all:

<Upgrade Id='$(var.UpgradeCode)'>
   <UpgradeVersion 
               OnlyDetect='yes' 
               Property='OLDERFOUND' 
               Minimum='0.0.0' 
               Maximum='$(var.Version)'
               IncludeMaximum='no' 
               IncludeMinimum='yes' />
</Upgrade>

On OLDERFOUND a dialog whith a combobox is shown. I dynamically add items to the combobox using a c# CustomAction:

[CustomAction]
public static ActionResult FillVersionList(Session xiSession)
{
    View view = xiSession.Database.OpenView("SELECT * FROM ComboBox");
    view.Execute();

    Record record = xiSession.Database.CreateRecord(4);
    //CURRENTVERSIONS is the name of the combobox property
    record.SetString(1, "CURRENTVERSIONS");
    record.SetInteger(2, 1);
    record.SetString(3, "foo");
    record.SetString(4, "foo");
    view.Modify(ViewModifyMode.InsertTemporary, record);

    record = xiSession.Database.CreateRecord(4);
    record.SetString(1, "CURRENTIVARVERSIONS");
    record.SetInteger(2, 2);
    record.SetString(3, "bar");
    record.SetString(4, "bar");
    view.Modify(ViewModifyMode.InsertTemporary, record);

    view.Close();
    return ActionResult.Success;
}

What I can't figure out how to do is

  • populate the combobox with all previous installed versions
  • and then update the one chosen by the user

I tried to figure out a way to read from the registry to get all versions (I have a registry key for each version installed), but haven't come up with anything. I have no idea how to specify which earlier version to update.


Solution

  • I dont understand why you want the user to select which version to upgrade. When your new product is distributed, it will have an upgrade code/product/package code combination which matches one of the previous installation and it can be used to upgrade ONLY that installation. You wont be able to change that behaviour based on user's decision.

    Read more about the upgrade code/product code here:

    UPGRADE CODE Product vs package vs upgrade code