I have a custom action which I need to execute only once during install or upgrading.
What happens is that the custom action is being executed twice if there is an older version of the same product already installed on the system. However the custom action is executed only once when there is no previous version installed on the system (clean install).
I have modified the condition for the custom action. Now when upgrading the custom action is only called once (which is correct) but in a clean install (with no previous version installed) the custom action is not being executed.
<CustomAction Id="MyCustomAction"
Return="check"
Execute="deferred"
Impersonate="no"
BinaryKey="MyCustomActions.CA.dll"
DllEntry="MyCustomAction" />
<InstallExecuteSequence>
<Custom Action="MyCustomAction"
Before="InstallFinalize">
<![CDATA[NOT Installed AND UPGRADINGPRODUCTCODE]]>
</Custom>
</InstallExecuteSequence>
Current behavior: Custom action is only executed once when upgrading but it is never called when installing.
Expected behavior: Custom action is executed only once when upgrading or installing.
I would say that you need an OR rather then an AND."NOT Installed" covers clean installation "UPGRADINGPRODUCTCODE" covers upgrade installation.
When upgrading NOT Installed is false and UPGRADINGPRODUCTCODE is empty for the already installed version. So you should be fine. I would also add NOT REMOVE and NOT REINSTALLMODE to disable execution on uninstall (where your CA is called in the already installed version while upgrading) and repair.