Jerode
Jerode

Reputation: 500

Check for later versions before uninstalling - WIX

If multiple versions of the same product are installed, can a property be used to check for the a newer version and add a condition message and prevent an uninstall?

Use case: Both WebSite 1.0.0 and WebSite 1.0.1 are installed on the webserver using the MSI package. When WebSite 1.0.0 is being uninstalled, I need to be able to prevent this if a newer version exists.

I considered using conditions but not sure if this is the best way to go.

<Condition Message="Newer version of the product must be removed">
    Installed OR PRODUCTVERSION > 1.0.0
</Condition>

When WebSite 1.1.0 is installed it will remove the previous version because it has the base set of files needed.

Upvotes: 0

Views: 83

Answers (2)

PhilDW
PhilDW

Reputation: 20790

If you need to prevent the manual uninstall of 1.0.0 then you need a search for (say) a component Id that exists only in the later versions, and you'd need to know what they are in the older versions so that the older versions can predict the future. Or you need the later versions to create registry entries that 1.0.0 can know in advance and search for during uninstall. The major upgrade search won't find anything because a major upgrade FindrelatedProducts search doesn't run during uninstall. You need a search, component, registry or something that 1.0.0 knows will be in a later version. Then use that property in a launch condition to prevent uninstall.

Another possibility would be a custom action that calls MsiEnumrelatedProducts() or equivalent on the upgrade code. This will return a series of ProductCodes for which you can call MsiGetProductInfo() to get the product version, and then check for whatever values are relevant. This has the advantage that the older product doesn't need to know in advance registry entries or component Ids because upgrade codes are more predictable and they are more unlikely to change in a series of products.

Upvotes: 1

Christopher Painter
Christopher Painter

Reputation: 55601

The MajorUpgrade element handles all of this with 1 attribute.

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

If you are using IsWiX (CodePlex) project templates this is authored by default out of the box. The idea is to cover the most common requirements and use cases so you don't even know you have a problem in the first place.

Upvotes: 2

Related Questions