Ronald Korze
Ronald Korze

Reputation: 828

WIX: Prevent only CERTAIN older versions from being updated

We have some product, that uses WIX as installer technology. Upgrade handling in the installer is handled by he MajorUpgrade element

<Wix>
  <Product Id="..." Name="..." Language="..."
    Version="..." Manufacturer="..."
    UpgradeCode="...">
...

    <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" AllowSameVersionUpgrades="yes" />
  </Product>
</Wix>

As you can see, we supported upgrades from all older version until now, however we have to change this a bit, so that only versions newer than a certain version can be upgraded, while older versions receive an error message and upgrade fails.

From what I've researched, this should be doable with the Upgrade element (as described in https://www.firegiant.com/wix/tutorial/upgrades-and-modularization/checking-for-oldies/)

My question now:

Update

Thanks for the replies and answers, my used solution is the following:

<Wix>
  <Product Id="..." Name="..." Language="..."
    Version="..." Manufacturer="..."
    UpgradeCode="My_upgrade_code">
...

    <InstallExecuteSequence>
...
      <Custom Action='UpdateFromVersionNotSupported' After='FindRelatedProducts'>UNSUPPORTEDUPDATEVERSIONFOUND</Custom>
...
    </InstallExecuteSequence>
    <MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" AllowSameVersionUpgrades="yes" />

    <Upgrade Id='My_upgrade_code'>
        <UpgradeVersion OnlyDetect='yes' Property='UNSUPPORTEDUPDATEVERSIONFOUND' Maximum='Oldes_version_where_update_is_allowed' IncludeMaximum='no' />
    </Upgrade>

    <CustomAction Id='UpdateFromVersionNotSupported' Error='Updates are only supported from version ?? or later' />

  </Product>
</Wix>

Upvotes: 3

Views: 461

Answers (2)

Stein &#197;smul
Stein &#197;smul

Reputation: 42216

There should be a few approaches:

  1. New UpgradeCode: Changing the upgrade code would decouple the older versions and the newer ones? You can add both upgrade codes to the upgrade table and handle them differently. See the image below and this answer:

    Upgrade code

  2. Versioning: You can also use version matching to upgrade only certain MSI versions. Upgrade Table documentation. In other words set the max and min versions to target with each upgrade table entry. You can keep adding rows to handle different versions differently. Something like this (just a rough mock-up):

    InstallShield Upgrade Table

WiX Constructs: You can mix and match the modern WiX convencience element with the older and more flexible elements. See this answer.

Side-By-Side MSI: Note that if you want to install the same MSI twice on the same computer interference will result unless you do work to isolate the instances (COM servers, file associations, services, etc... - anything machine-wide and interference capable). The worst of it is generally things registered system-wide accessed via the registry (unless it is multi-instance capable). More technical information here. Virtualization can help? See the links for details.

Upvotes: 2

Christopher Painter
Christopher Painter

Reputation: 55601

You'll need to use the Upgrade element.

https://wixtoolset.org/documentation/manual/v3/xsd/wix/upgrade.html

https://wixtoolset.org/documentation/manual/v3/xsd/wix/upgradeversion.html

You need to write 2 rules. One that allows an upgrade for version X or higher. This can be your standard MajorUpgrade element. And another that detects a version <X and triggers a Condition that displays a message informing the user to uninstall first and blocks installation.

Upvotes: 1

Related Questions