Custom action condition to run for a new or upgraded product.

I have a custom action condition (in Visual Studio Web Setup Project) that I want  to run for installation of a new or upgraded product. I do not want to run it on repair (and also during uninstall).

First of all I tried “Not Installed” condition. But it doesn’t work for version upgrade. I’ve tried

Not Remove=”ALL” but it also doesn’t work for version upgrade( it seems that deleting previous version set the property Remove=”ALL”)

I’ve tried UPGRADINGPRODUCTCODE , but it is set for the previous version, not for the version being installed.

The article (sorry, in Russian only) suggests to use IS_MAJOR_UPGRADE ,but the property is applicable for InstalledShield only.

Finally I found combination that is working:

Note that brackets are important to evaluate NOT first and condition is case-sensitive).

PREVIOUSVERSIONSINSTALLED is not documented property, I found it when reading msi log and in a few posts(e.g. here: “If the search at the start of the install detects
an older version, it creates the PREVIOUSVERSIONSINSTALLED property,
case-sensitive.“ ).

NOTE: I found that custom action with condition
(Not Installed) OR PREVIOUSVERSIONSINSTALLED works on my development machine, but it was not invoked on my deployment machine until I changed target virtual directory. Mistery ???