views:

146

answers:

1

Hi all, I have a custom action that removes various directories as part of the uninstall process. I want to call this action at different points in the install sequence depending on what's being done:

  • During an install, don't run the custom action
  • During an upgrade, run the custom action after RemoveExistingProducts
  • During an uninstall, run the custom action after RemoveFolders

I can likely get each one of these to work individually, but how do I get them to work together how I want. I tried something like this (some code take from here):

<InstallExecuteSequence>

  <Custom Action="PreventDowngrading" After="FindRelatedProducts">
    NEWERPRODUCTFOUND AND NOT Installed
  </Custom>

  <LaunchConditions After="AppSearch" />
  <RemoveExistingProducts Before="InstallInitialize" />

  <!-- NEW _> Clean old files AFTER uninstall during an upgrade -->
  <Custom Action="CleanUp"  After="RemoveExistingProducts" >
    UPGRADINGPRODUCTCODE
  </Custom>

  <!-- NEW _> Clean old files LAST during an uninstall -->
  <Custom Action="CleanUp"  After="RemoveFolders" >
    (NOT UPGRADINGPRODUCTCODE) AND (REMOVE="ALL")
  </Custom>

</InstallExecuteSequence>

But get a duplicate symbol error when I do a build. Any help will be greatly appreciated!

A: 

A custom action can be in a sequence only once. I have some bigger concerns though: what type of upgrade are you doing? A major upgrade does a uninstall of the previous product so your CA might run twice the way you are describing it.

I would tread really lightly here. Can you possibly use the WiX RemoveFolder element ( MSI RemoveFile table ). This will be alot easier and reliable to implement. If you must use a custom action I would use component action states to determine when it should run rather then more generic properties like shown above.

Christopher Painter
It is a major upgrade I'm doing, but the uninstall doesn't delete files added to the folder, so it often leave stuff lying around after the uninstall. What advantages would using component action states give me over the properties I've used? Cheers, Matt.
mattyB
Take a look at the <RemoveFolder/> element. You can specify a Directory Id and FileSpec and this will teach MSI to do the extra cleanup for you. Then you don't have to mess with all these risky custom actions.
Christopher Painter
Won't <RemoveFolder/> only work if the folder is empty? In the end I've use a custom action but would prefer to do it entirely within the installer next time.
mattyB
Do you have 1 folder or a tree of folders to remove? Correct, it only deletes if empty ( which rules out trees ) but if you say *.* and have no subfolders ( or if you know the names of your subfolders and say *.* for them also ) then you should be ok.
Christopher Painter
I've got a tree of subfolders that the application writes files to, so I don't know at the point of uninstall what new files have been placed in the folder.
mattyB
Do you know the all of the folder names in advance? If not, could the application be redesigned so that you did? Once you get that accomplished then it's fairly easy to handle the cleanup in MSI.
Christopher Painter