Reputation: 10650
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.
Upvotes: 1
Views: 768
Reputation: 1080
From https://stackoverflow.com/a/17608049/1721136 I take
<SetProperty Id="_INSTALL" After="FindRelatedProducts" Value="1">
<![CDATA[Installed="" AND PREVIOUSVERSIONSINSTALLED=""]]>
</SetProperty>
<SetProperty Id="_UPGRADE" After="FindRelatedProducts" Value="1">
<![CDATA[PREVIOUSVERSIONSINSTALLED<>"" ]]>
</SetProperty>
and then
<InstallExecuteSequence>
<Custom Action="MyCustomAction"
Before="InstallFinalize">
<![CDATA[_INSTALL OR _UPGRADE]]>
</Custom>
</InstallExecuteSequence>
Or, if this does not work, try to run custom action only with the new installer and use property
<SetProperty Id="_NEWINSTALLER" After="FindRelatedProducts" Value="1">
<![CDATA[NOT UPGRADINGPRODUCTCODE]]>
</SetProperty>
Upvotes: 0
Reputation: 574
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.
<![CDATA[(NOT Installed OR UPGRADINGPRODUCTCODE) AND NOT REMOVE AND NOT REINSTALLMODE]]>
Upvotes: 0