[wix-users] Conditionally remove a folder using RemoveFolderEx?
Markus Kramer
markuskramerigitt at gmail.com
Fri Oct 2 09:43:24 PDT 2020
Hi
I try to use *RemoveFolderEx *to remove a cache directory only on
uninstall, but keep the cache during major upgrades.
So far I am unable to prevent the removal of the cache during a major
upgrade.
I use the condition *NOT WIX_UPGRADE_DETECTED* to detect an upgrade, but
nonetheless the component is unregistered and registered again during
upgrade, and RemoveFolderEx removes the cache.
Can I conditionally leave a component installed?
Can I add a condition to *RemoveFolderEx*?
Thanks
The cache directory has id *VARFOLDER *and the component that holds
*RemoveFolderEx
*is called *RemoveFolderEx_VARFOLDER_Component*
<?xml version="1.0" encoding="UTF-8"?>
<Wix
xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product
Name='Foobar'
Version="$(var.InternalVersion)"
Manufacturer='Acme Ltd.'
Language='1033'
UpgradeCode='802c19d8-ace7-4f76-bf00-7132df6a92a9'
Id='*'
>
<Package InstallerVersion='450' Compressed='yes'
InstallScope="perMachine" Platform="x64" />
<MediaTemplate EmbedCab="yes" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName]
is already installed." />
<InstallExecuteSequence>
</InstallExecuteSequence>
<Directory Id='TARGETDIR' Name='SourceDir'>
<Directory Id='INSTALLFOLDER' Name='AcmeFoobar'>
<Directory Id='BINFOLDER' Name='bin'>
<Component Id='MainExecutable' Win64='yes'
Guid="108c2034-c33a-4d0f-a82f-ebeac2a840cb">
<File Id='FoobarEXE' Name="$(var.Foobarexefile)"
Source="$(var.Foobarexefile)" KeyPath='yes'/>
</Component>
</Directory>
<Directory Id='VARFOLDER' Name='var'>
</Directory>
</Directory>
</Directory>
<Feature Id='Complete'>
<ComponentRef Id='MainExecutable'/>
<ComponentRef Id="RemoveFolderEx_VARFOLDER_Component"/>
<ComponentRef Id="RemoveFolderEx_BINFOLDER_Component"/>
</Feature>
</Product>
<Fragment Id="RemoveFolderEx_Fragment">
<?define RegDir="SOFTWARE\AcmeFoobar"?>
<?define RegVal_BINFOLDER="RememberForRemoveFolderEx_BINFOLDER"?>
<?define RegVal_VARFOLDER="RememberForRemoveFolderEx_VARFOLDER"?>
<Property Id="BINFOLDER">
<RegistrySearch Root="HKLM" Key="$(var.RegDir)" Type="raw"
Id="APPLICATIONFOLDER_REGSEARCH_BIN"
Name="$(var.RegVal_BINFOLDER)" />
</Property>
<Property Id="VARFOLDER">
<RegistrySearch Root="HKLM" Key="$(var.RegDir)" Type="raw"
Id="APPLICATIONFOLDER_REGSEARCH_VAR"
Name="$(var.RegVal_VARFOLDER)" />
</Property>
<DirectoryRef Id='BINFOLDER'>
<Component Id="RemoveFolderEx_BINFOLDER_Component"
Guid="b70cd37e-b13b-4c1f-b1f0-095a695c27c8" Win64='yes'>
<RegistryValue Root="HKLM" Key="$(var.RegDir)"
Name="$(var.RegVal_BINFOLDER)"
Type="string" Value="[BINFOLDER]" KeyPath="yes"/>
<util:RemoveFolderEx Property="BINFOLDER" On="uninstall"/> <!--
uninstall INCLUDES UPGRADE -->
</Component>
</DirectoryRef>
<!-- Codition has no effect -->
<DirectoryRef Id='VARFOLDER'>
<Component Id="RemoveFolderEx_VARFOLDER_Component"
Guid="301efe0b-a8b3-419d-b787-3478eb56e252" Win64='yes'>
<Condition>NOT WIX_UPGRADE_DETECTED</Condition>
<RegistryValue Root="HKLM" Key="$(var.RegDir)"
Name="$(var.RegVal_VARFOLDER)"
Type="string" Value="[VARFOLDER]" KeyPath="yes"/>
<util:RemoveFolderEx Property="VARFOLDER" On="uninstall"/> <!--
uninstall INCLUDES UPGRADE -->
</Component>
</DirectoryRef>
</Fragment>
</Wix>
More information about the wix-users
mailing list