13

I have some custom actions that I only want to execute in an upgrade scenario.

I am trying to set some properties, for example "MYPROPERTY"... When I come in via a standard install, I can set them, and an example of that XML is as follows...

<Custom Action="SetMyPropertyToOn" After="exampleActionRuuningBeforeThisOne"> (ENABLEMYPROPERTY_CB) AND (NOT ENABLEMYPROPERTY_CB="0") AND (NOT ENABLEMYPROPERTY) AND (NOT Installed)</Custom>

It runs in a normal install... I would also like it to run in an upgrade scenario.

1
  • A Major Upgrade or a Minor Upgrade? If you are doing a minor upgrade then Installed would be true and this would evaluate to false. Aug 30, 2013 at 13:19

1 Answer 1

34

I use this in all my setups:

    <SetProperty After="FindRelatedProducts" Id="FirstInstall" Value="true">
        NOT Installed AND NOT WIX_UPGRADE_DETECTED AND NOT WIX_DOWNGRADE_DETECTED
    </SetProperty>
    <SetProperty After="SetFirstInstall" Id="Upgrading" Value="true">
        WIX_UPGRADE_DETECTED AND NOT (REMOVE="ALL")
    </SetProperty>
    <SetProperty After="RemoveExistingProducts" Id="RemovingForUpgrade" Sequence="execute" Value="true">
        (REMOVE="ALL") AND UPGRADINGPRODUCTCODE
    </SetProperty>
    <SetProperty After="SetUpgrading" Id="Uninstalling" Value="true">
        Installed AND (REMOVE="ALL") AND NOT (WIX_UPGRADE_DETECTED OR UPGRADINGPRODUCTCODE)
    </SetProperty>
    <SetProperty After="SetUninstalling" Id="Maintenance" Value="true">
        Installed AND NOT Upgrading AND NOT Uninstalling AND NOT UPGRADINGPRODUCTCODE
    </SetProperty>

You can then schedule your custom action to only run on upgrades:

<Custom Action="NameOfCustomAction" Before="InstallFinalize"><![CDATA[Upgrading= "true"]]></Custom>
9
  • Thanks Natalie, I only have one small issue with this. Somehow, I always seem to get into the "FirstInstall" part, and then skipping the rest, even on upgrade... The others always skip.
    – Slippy
    Aug 30, 2013 at 12:48
  • Strange, Ive never experienced that. Could you post your log file maybe that would help? Aug 30, 2013 at 13:08
  • 6
    The properties WIX_UPGRADE_DETECTED and WIX_DOWNGRADE_DETECTED assumes the MajorUpgrade element was used. User defined Upgrade rules may have different ActionProperty names and a minor upgrade wouldn't have these at all. The OP didn't say what kind of upgrade he was doing. Aug 30, 2013 at 13:21
  • 2
    Tested, seems working fine, but when you install not ALL features and launch the installer again to choose the "Remove" option, the "Maintenance" flag is ON during both runs. However I'd expect "Uninstalling" ON for the second run. The "Uninstalling" condition fails because REMOVE <> "ALL", it's equal to a list of installed features instead.
    – Alex Klaus
    Sep 15, 2015 at 4:25
  • 1
    @NatalieCarr Thanks so much for posting this! I came across it recently and now, years later, it's still valid and exactly what I needed to solve a similar problem.
    – Dave
    Jun 14, 2017 at 11:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.