0

I have a custom action which during upgrade,removes certain files before installFiles which puts the new files back.What I am noticing is the action is called 2 times. 1.Gets called and deletes the file. 2. InstallFiles copies the new files back. 3.Again gets called and deletes the file.(Should not happen).

My custom action looks like -

<InstallExecuteSequence>
            <RemoveExistingProducts After="InstallFinalize" />
            <Custom Action="NEWER_VERSION_PRESENT" After="FindRelatedProducts">
         NEWER_VERSIONS
            </Custom>
            <Custom Action="DeleteourFiles" Before="InstallFiles"></Custom>
</InstallExecuteSequence>

I read somewhere that for upgrade scenario this custom action gets called twice.I want to know how to prevent it getting called for the second time. basically want my custom action to delete certain files of older version before it puts the new files .What condition should I use?

Somesh Dhal
  • 336
  • 2
  • 15

1 Answers1

2

Your old installation is getting removed and deleting the files.

<RemoveExistingProducts After="InstallFinalize" />

Schedules the run of the old installer to uninstall it after InstallFinalize which then runs your installation as an uninstall.

<Custom Action="DeleteourFiles" Before="InstallFiles"></Custom>

Has no condition on it so it will always run every time the install runs whether it is installing or uninstalling or upgrading.

If you want it to run during the upgrade install and when you explicitly uninstall you will need to add

<Custom Action="DeleteourFiles" Before="InstallFiles">NOT UPGRADINGPRODUCTCODE</Custom>

During upgrades the install you ran will run the already installed (older version) installer and define UPGRADINGPRODUCTCODE as its own Product code. So, if you say only run this custom action when the UPGRADINGPRODUCTCODE is not defined, it will run it when you upgrade once in the upgrading install and not in the older one and then also when you explicitly uninstall the product.

Because of how you've authored this though, you will still have a problem upgrading all previously released installations. You can work around this by changing your scheduling of removing the existing products.

If you use

<RemoveExistingProducts After="InstallInitialize" />

it will uninstall the previous version at the start instead of the end which should work around running that DeleteourFiles custom action twice.

Another thing to mention is that usually you don't explicitly schedule "RemoveExistingProducts" in the InstallExecuteSequence tags

Normally you will define this scheduling in the MajorUpgrade tag

Brian Sutherland
  • 4,698
  • 14
  • 16
  • If I reschedule RemoveExistingProducts after InstallInitialize do I still need to provide the condition for custom action? – Somesh Dhal Sep 28 '17 at 11:27
  • You should since that is the correct behaviour. You will need to reschedule RemoveExistingProducts since the currently installed version of your product won't get the updated condition so it will still remove the files when it uninstalls. – Brian Sutherland Sep 28 '17 at 14:17