Delete a folder using Wix - wix

I recently tried to create an installer for my application using Wix. When I uninstalled the application all my folders and files were deleted except some created at run time by the application. After some research I found out that the reason was because those folders and files were created after the install proccess. I also found out that what I wanted to use would be the element RemoveFolderEx. Unfortunatly, I am having some trouble to use the tag. This is my current code that doesn't work:
<Feature Id="ProductFeature" Title="App" Level="1">
...
<ComponentRef Id="deeletappdata" />
</Feature>
<Component Id="deeletappdata" Guid="*" Directory="AppDataFolder">
<util:RemoveFolderEx Id="RemoveAppDataAppContent" On="uninstall" Property="AppDataAppFolderDir" />
</Component>
<Directory Id="AppDataFolder">
<Directory Id="AppDataAppFolderDir" Name="$(var.Application)"/>
</Directory>
How can I use the element RemoveFolderEx?

Related

Installer (wix built msi) does not remove a feature element (a directory) during uninstallation

I am having issues getting my installer (msi) to remove a feature based component during uninstallation. The feature element, as per below, contains conditional component group references, which are to a directory id and a number of other components in another fragment (e.g., iis:WebAppPool):
Product.wxs
<Feature Id="StandardIntegration" Level="1" Title="StandardIntegration">
<ComponentGroupRef Id="SERVICES"/>
<!-- Integration Services IIS -->
<ComponentRef Id="comp1"/>
<ComponentRef Id="comp2"/>
<ComponentRef Id="comp3"/>
<ComponentRef Id="comp4"/>
<Condition Level="0">
<![CDATA[HAS_FEATURE_SET <> "true"]]>
</Condition>
</Feature>
OtherFragment.wxs
<DirectoryRef Id="INSTALLDIR">
<Directory Id="InstancePath">
<Directory Id="SERVICES" Name="Services"/>
</Directory>
</DirectoryRef>
<Component Id="comp1" Directory="SERVICES" Win64="yes" KeyPath="yes" Guid="$(var.c)" MultiInstance="yes" Shared="no">
<iis:WebAppPool Id="wbpoolid" ManagedRuntimeVersion="v4.0" Name="CMP_[NAME]" User="AppPoolUser" Identity="other" RecycleMinutes="0" RecycleRequests="0" ManagedPipelineMode="integrated">
</iis:WebAppPool>
....
All other components referred (including the ones that contains the iis web app pool element) are removed correctly during uninstallation, but the directory ("SERVICES") is not... and it's the only file directory that's not being removed. (E.g., all other files installed by the msi are being correctly removed.)
Any help would be much appreciated, thanks!

WiX Ice64 error for shortcut parent directory

I am trying to create a start menu shortcut for an application using WiX, the problem is that I am receiving an Ice64 error stating that the parent directory of the shortcut directory is not in the RemoveFile table.
I do not want to remove this parent folder (organisation folder) on uninstall as other applications may have shortcuts in other children of it.
My code looks like
<Feature Id="ProductFeature" Title="MyApplication" Level="1">
<ComponentGroupRef Id="Components" />
<ComponentRef Id="ProfilesShortcut"/>
</Feature>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="OrgDir" Name="OrganisationName">
<Directory Id="AppDir" Name="MyApplication" />
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="ProgFilesOrgDir" Name="OrganisationName">
<Directory Id="ProgFilesAppDir" Name="MyApplication" />
</Directory>
</Directory>
</Directory>
</Fragment>
<Fragment>
<DirectoryRef Id="ProgFilesAppDir">
<Component Id="ProfilesShortcut" Guid="*">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="MyApplication"
Description="My Application"
Target="[#MyApplication.exe]"
WorkingDirectory="AppDir"/>
<RemoveFolder Id="ProgFilesAppDir" On="uninstall"/>
<RegistryValue Root="HKCU" Key="Software\Organisation\MyApplication" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
</DirectoryRef>
</Fragment>
Feel free to add the remove file element to your shortcut component.
Remove an empty folder if the parent component is selected for installation or removal.
The RemoveFolder element will only remove empty folders so if your product is not the only part of that suite installed it will leave the parent folder alone since other products will have put files/folders there. Consider the scenario where your product is either the only one installed (should remove the folder) or is the last one to be uninstalled from the suite (should remove the folder). In these two cases the folder should get removed. The order of RemoveFolder elements get defined might matter so I would test putting the ProgramFilesOrgFolder remove element before and after ProgFilesAppDir remove element just to see if one of them fails.
Alternatively you can just suppress ICE64 but then you will leave a folder behind once all the products are uninstalled. Not a huge deal really but might be annoying to some users.

WiX shortcut only project

I have my bootstrapper project and I need to add a shortcut only when another third part msi is selected on bootstrapper's UI. So I end up with another little msi like this (removing not relevant data):
<Wix >
<Product >
<Package />
<MajorUpgrade />
<MediaTemplate />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramMenuFolder">
<Directory Id="ApplicationProgramsFolder" Name="FolderName">
</Directory>
</Directory>
</Directory>
<Component Id="ApplicationShortcut" Guid="PUT-GUID-HERE" Directory="ApplicationProgramsFolder">
<Shortcut Id="ApplicationStartMenuShortcut"
Name="App"
Description="desc"
Target='"[ProgramFiles64Folder]Folder1\Folder2\app.exe"'
Arguments=' -n name'
/>
<RemoveFolder Id="RemoveProgramMenuDir" Directory="ApplicationProgramsFolder" On="uninstall" />
<RegistryValue Root="HKCU" Key="Software\ACME\App" Name="installed" Type="integer" Value="1" KeyPath="yes"/>
</Component>
<Feature Id="ProductFeature" Title="Shortcuts" Level="1">
<ComponentRef Id="ApplicationShortcut" />
</Feature>
</Product>
But I get
ICE71: The Media table has no entries.
That source doesn't compile anyway because of issues with missing languages, productcodes and so on. It would have helped if you'd posted a complete working example. After fixing those issues and seeing ICE71, you basically need to delete mediatemplate and add a proper media entry such as (in angle brackets)
Media Id="1" Cabinet="product.cab" EmbedCab="yes"
then all you get is warning LGHT1079 : The cabinet 'product.cab' does not contain any files. If this installation contains no files, this warning can likely be safely ignored. Otherwise, please add files to the cabinet or remove it.
I would just augment the third party MSI with a transform that creates a shortcut when that MSI is installed. This way you don't have to do anything special in the bootstrapper.

WiX merge module dependencies

I have an issue with some existing installers which I have repeated in a simple test case as follows:
Installer1 installs App1 and LibraryA(v1).
Installer2 installs App2, LibraryA(v2) and LibraryB. LibraryA(v2) requires LibraryB, which is why LibraryB is now installed. LibraryA(v1) had no such dependency. LibraryA(v2) should overwrite LibraryA(v1).
If I run Installer1 then Installer2, then uninstall Installer2, LibraryB gets removed, but LibraryA remains at v2 (sensible - I wouldn't expect it to revert to a prior version).
Forgetting my existing problem and imagine I was starting from scratch, how would you suggest I construct my WiX project to cope with such a situation? In my case, all of the libraries are defined as merge modules - something I'm not in a position to change (wixlibs are out of the question).
I have tried, to no effect, to use a Dependency element to create a dependency between the LibraryA(v2) merge module and the LibraryB merge module - it just seems to issue a linker warning if I forget to reference LibraryB in the installer, rather than creating an actual dependency.
The .wxs scripts in my test case look something like this (they all install to the same folder for ease of testing):
LibraryA(v1).wxs:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="MergeRedirectFolder">
<Component Id="LibraryAComponent" Guid="d98dd742-c3d3-4aee-8d84-87f2b3c837dc">
<File Source="v1\LibraryA.dll" />
</Component>
</Directory>
</Directory>
LibraryA(v2).wxs:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="MergeRedirectFolder">
<Component Id="LibraryAComponent" Guid="d98dd742-c3d3-4aee-8d84-87f2b3c837dc">
<File Source="v2\LibraryA.dll" />
</Component>
</Directory>
</Directory>
<Dependency RequiredId="LibraryBMergeModule.DD524F28_EAE0_47B8_A895_3AF2F7A7361A" RequiredLanguage="1033"/>
LibraryB.wxs:
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="MergeRedirectFolder">
<Component Id="LibraryBComponent" Guid="46e6e0da-2a99-4f0d-bed2-e764e16b9eed">
<File Source="LibraryB.dll" />
</Component>
</Directory>
</Directory>
App1.wxs:
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" DiskId="1" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="WiXTest" Name="WiXTest">
<Merge Id="LibraryAv1" Language="1033" SourceFile="LibraryAv1.msm" />
<Component Id="App1Component" Guid="93D11AFF-5307-4355-B261-0096775B6A89">
<File Source="App1.exe" />
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="Libraries" Title="Shared Files" Level="1">
<MergeRef Id="LibraryAv1" />
</Feature>
<Feature Id="App" Title="Application" Level="1">
<ComponentRef Id="App1Component" />
</Feature>
App2.wxs:
<Media Id="1" Cabinet="media1.cab" EmbedCab="yes" />
<Directory Id="TARGETDIR" DiskId="1" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="WiXTest" Name="WiXTest">
<Merge Id="LibraryB" Language="1033" SourceFile="LibraryB.msm" />
<Merge Id="LibraryAv2" Language="1033" SourceFile="LibraryAv2.msm" />
<Component Id="App2Component" Guid="173C71B6-E403-4AC1-894D-06799C6782A4">
<File Source="App2.exe" />
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="Libraries" Title="Shared Files" Level="1">
<MergeRef Id="LibraryB" />
<MergeRef Id="LibraryAv2" />
</Feature>
<Feature Id="App" Title="Application" Level="1">
<ComponentRef Id="App2Component" />
</Feature>
I'm guessing that this is entirely the wrong way to go about things and am looking for some pointers to bring me back on track. It feels like you need to have a PhD in Windows Installer in order to use WiX correctly.
I am no WIX expert but yes for MSI you need at least a PhD. At first you should know the rules about MSI components:
What Every Developer Should Know About MSI Components
From painful experience I do know that if several MSIs bring in the same components it is no good. If possible I would strive for the single source principle so that your libs are installed always by the same MSI (let it be a infrastructure MSI). Your application MSIĀ“s then simply check if the infrastructure has been installed and that was it.
Coming back to your question what you should do with your merge modules. I would create for each merge module an extra msi (yes customers do not like crowed installed software catalogs) to be sure that if you are in need to service the libraries you have full freedom.
I do not know your software structure but it could be that you will need LibraryA v1 and v2 at the same time so you should think about deploying your libraries to the WinSxS cache or if they are managed the GAC. Or you come up with something similar in your folder structure or file name convention.

Wix installer and disabled features

I'm using Wix3 beta with Feature Tree UI. I'm installing several assemblies as separate components into a custom subdirectory inside ProgramFiles, as well as into GAC. Additionally I would like to package DEBUG versions of the same assemblies as one component and let the user decide whether to install them or not. Now this feature with debug assemblies is disabled by default, but the debug assemblies are installed regardless.
Below the relevant snippet:
<DirectoryRef Id="INSTALLDIR">
<Directory Id="bin" Name="bin">
<Directory Id="Debug" Name="Debug">
<Component Id="DebugComponent" Guid="PUT-GUID-HERE">
<File Id="DebugAssemblyXXX" DiskId="1" Source="Debug\XXX.dll"></File>
</Component>
</Directory>
<Directory Id="Release" Name="Release">
<Component Id="ReleaseComponent" Guid="PUT-GUID-HERE">
<File Id="ReleaseAssemblyXXX" DiskId="1" Source="Release\XXX.dll"></File>
</Component>
</Directory>
</Directory>
</DirectoryRef>
<Feature Id="All" ConfigurableDirectory="INSTALLDIR" Title="Title" Level="1"
Display="expand" AllowAdvertise="no" Absent="disallow" Description="Desc">
<Feature Id="DebugAssemblies" Title="Debug Assemblies" Level="1000" Absent="allow"
AllowAdvertise="no" Description="Debug versions of assemblies.">
<ComponentRef Id="DebugComponent" />
</Feature>
<Feature Id="ReleaseFeature1" Title="Feature" Level="3"
AllowAdvertise="no" Description="Another description">
<ComponentRef Id="ReleaseComponent"/>
</Feature>
</Feature>
The weird thing is that if I run the msi file again and go to "Change" and disable the Debug feature, the Debug assemblies will be deleted, e.g. the logic works fine this time.
The default INSTALLLEVEL is 3.
Any suggestions?
In case somebody else gets stuck with this: apparently the top-level feature should not be named "All" as in my case - it might have some default meaning to Wix/Windows Installer. Upon renaming it to something else everything works as expected.