1

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.

2 Answers 2

0

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]]>
Sign up to request clarification or add additional context in comments.

5 Comments

Still without working. Now what happens is: Installer starts, detects the old version and uninstall its and the custom action is executed. Then it starts copying files of the new app and again at the end of copying files and before install finalizes, the custom action is again executed a second time. I am interested in only execute one time the custom action in all the process. Otherwise, if I install it from scratch (clean installation, no previous install on system), then the custom action is only executed just 1 time (in this case is correct):
The problem is that you have the custom action executed on uninstall of the existing installation. You can only fix this for future versions. Or by backup and restore before the upgrade actions are executed in the new setup.
Don't understand what do you mean by "only fix this for future versions". Isn't there a way to tell Wix to execute custom action only once after it uninstalls the previous before and after copying files of the new installation?
The thing is that 2 installers are executed on upgrade. The new installer calls uninstall of the old installer (that of the currently installed software) and if the condition is wrong on the old installer your CA is called there.
yep,this is the big problem, two installers are executed when upgrading. I have tried a lot of combinations of conditions,, but none works. But although they are two separate installer, the first one is to uninstall and the second one to install, so there is no WiX variable that is set only on uninstalling and another only set on installing? Also don't understand whether in the first installer that is performing an uninstallation,, why then it is copying files?
0

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.