Xoph
Xoph

Reputation: 37

How do I conditionally uninstall files in WiX?

I have a WiX package that should always deliver files, but should only uninstall the files when a condition is met. The condition is that common files should not be uninstalled if another version of the product is installed (we are not supporting true upgrades, our upgrade is installing the files to a new folder that has the version of the package and installing new versions of the common files).

I realize this can be achieved by using the same GUIDs across components or using merge modules, but I also have to account for the fact that I have legacy packages from InstallShield that could be installed. Unfortunately, the designers of those packages had no idea of what was going on with installers, and they installed files to a temp directory, then copied them to a new location, so Windows Installer has no knowledge that the files are installed.

I have tried a couple different things.

Approach #1:

<Component Id="myfile.dll" Guid="{YOUR-GUID-HERE}" Transitive="yes" >
  <Condition>OTHER_VERSIONS_PRESENT ~= "FALSE"</Condition>
  <File Id="myfile.dll" KeyPath="yes" Source="$(var.PATH_TO_BIN_FILES)myfile.dll" />
</Component>

Approach #2:

<Component Id="myfile.dll" Guid="{YOUR_GUID_HERE}" Permanent="yes" >
  <File Id="myfile.dll" KeyPath="yes" Source="$(var.PATH_TO_BIN_FILES)myfile.dll" />
</Component>
<Component Id="myfile.dll_remove" Guid="{YOUR_GUID_HERE}" Transitive="yes" >
  <RemoveFile Id="myfile.dll_remove" Name="myfile.dll" On="uninstall" />
    <Condition>OTHER_VERSIONS_PRESENT ~= "FALSE"></Condition>
</Component>

Additional Info

Here is my property that I am using with the custom actions and the condition:

<Property Id="OTHER_VERSIONS_PRESENT" Value="FALSE" />

Here is my scheduling of the custom action that sets the OTHER_VERSIONS_PRESENT property. I have verified that it is correctly set to true or false, based on whether another version of the product is present.

<Custom Action="FindOtherVersionsOfProduct" After="CostFinalize" />

I have also tried the above approaches with CDATA wrapped around the condition, but this also failed. Additionally, I tried changing the install sequence of when I set the property. I've tried different conditions. But nothing has worked.

Thank you in advance for any support you can give me.

Edit: Approach 1 is working, but once I change it to be

<Condition>NOT Installed OR ((REMOVE ~= "ALL") AND (OTHER_VERSIONS_PRESENT ~= "FALSE"))</Condition>

it no longer works.

Upvotes: 0

Views: 1286

Answers (1)

PhilDW
PhilDW

Reputation: 20790

My suggestion is that both of those approaches are probably incorrect. The general solution used in all cases I can think of that both packages need to install the same files to same common location. A common merge module containing those components ensures that the Windows Installer sharing works, so uninstalling one product leaves the files behind for the remaining product (because ref counting is based on component ids and just decrements the count when a product is uninstalled). In other words it all just works without transitive components or conditions.

Upvotes: 0

Related Questions