Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

wix - how to delete non-empty folder

Tags:

c#

wix

I have read all topics on this site with problem like this, but not find what i need.

I have two versions of one program: old and new. In old version i have folder f1. In new version i have no this folder f1.

When installer of new programm detected old version, it delete this old version, but not folder f1.

How can i delete f1 from installer of new version?

      <Component Id ="deleteall"  Guid="AA11A32B-9E1E-458A-8C94-3EFEDA77E494" >
        <RemoveFolder Id='iDocDir' On='both' />
      </Component>

      <Directory Id="iDocDir" Name="iDocs">
      </Directory>

not working =(

like image 921
Risa Avatar asked Jul 30 '13 07:07

Risa


1 Answers

You should check out the RemoveFolderEx element in the UtilExtension. It does exactly what you want. Bob Arnson has blogged about it before.

<Component Id="deeletall" Guid="PUT-GUID-HERE">
    <util:RemoveFolderEx Id="RemoveiDocDir" On="uninstall" Property="iDocDir" />
</Component>

It works by writing temporary rowes to the RemoveFile table. There are restrictions to using this, however, as noted in the manual:

Because it might dramatically affect Windows Installer's File Costing, the temporary rows must be written before the CostInitialize standard action. Unfortunately, MSI doesn't create properties for the Directory hierarchy in your package until later, in the CostFinalize action.

An easy workaround for a typical use case of removing a folder during uninstall is to write the directory path to the registry and to load it during uninstall.

If you use custom actions to set properties, ensure that they are scheduled before the WixRemoveFoldersEx custom action.

And also in Bob's post:

As adding directories and files to be deleted affects MSI’s file costing, RemoveFolderEx has to do its thing before costing. Unfortunately, MSI doesn’t set up properties for target directories until after costing is complete.

If you already save your previous installation path (Rob explains how to do this here) in the registry, you're fine, as the AppSearch action runs before CostInitialize.

like image 71
Netfangled Avatar answered Oct 03 '22 02:10

Netfangled