How to prevent removal of IIS elements during upgrade

If you need to prevent IIS elements from being removed during upgrade, here is what you need to do:

An upgrade installation consists in two parts:

  1. the uninstallation of the old product version;
  2. the installation of the new product version.

An upgrade process can be detected by using two properties:

  • OLDPRODUCTS - this property is set in the upgrading MSI if the package finds an older version installed on the target machine;
  • UPGRADINGPRODUCTCODE - this property is set in the MSI which is being upgraded if the package is uninstalled by a newer version.

1. Prevent IIS elements to overwrite the existing website

This can be done through the Install condition field from the Website Settings.

The website should look like the one below:
Prevent iis elements to overwrite the existing website install condition

2. Do not remove IIS elements during the uninstall triggered by an upgrade

In order to do this, you can go in the Table Editor page (available starting with the Enterprise edition) and condition the AI_IISUninstall action from the InstallExecuteSequence table. The condition should look like the one below:

       ( (VersionNT >= 500) AND (REMOVE = "ALL") ) AND ( NOT UPGRADINGPRODUCTCODE );
       

Advanced Installer references IIS elements through the ProductCode of the installers. Different versions have different ProductCodes, thus the IIS element will not be removed during the uninstallation of the last product. For this, a CustomAction is required.

We recommend you to use a PowerShell script code, as specific cmdlets, as the ones below, being available in PowerShell:

The CustomAction needs to run When the system is being modified (deferred) and Run under the LocalSystem acocunt with full privileges (no impersonation).

Also, please check the 64-bit script box, if you intend to use 64-bit PowerShell script on 64-bit machines.

Condition the CustomAction so that it executes only when the uninstall is not triggered by an upgrade

The CustomAction should look like the one below:
Do not remove ii elements during the uninstall triggered by an upgrade customaction