Iman
Iman

Reputation: 21

How can one modify CPack generated WiX XMLs using a patch file?

I am trying to add the functionality to uninstall a previous version before installing a new version of a certain installer. The CPackWIX documentation page (https://cmake.org/cmake/help/v3.3/module/CPackWIX.html) is not clear about how to use CPACK_WIX_PROPERTY_PROPERTY or CPACK_WIX_PATCH_FILE to modify CPack generated WiX XMLs. Let's assume the following doesn't already exist in the CPack generated XMLs. Is there a way to add the following to them using a patch file?

<InstallExecuteSequence>
    <RemoveExistingProducts Before='InstallFinalize' />
</InstallExecuteSequence>

The documentation shows how one could add an environment element to a component. Is there a way we can do the above extending that logic?

Upvotes: 0

Views: 1081

Answers (1)

Arnaud
Arnaud

Reputation: 604

I had the same issue as you (uninstall previous version of a package) and had some troubles trying to use CPACK_WIX_PATCH_FILE so I thought about another solution: using CPACK_WIX_TEMPLATE macro and setting it to point a modified version of the default template.

The default template can be found here: https://github.com/Kitware/CMake/blob/master/Modules/Internal/CPack/WIX.template.in

I know it's not ideal since this file might change after CMake upgrade.

But the interesting is that I realized adding "RemoveExistingProducts" didn't work because this was already handled in the default template file (as part of MajorUpgrade).

The real issue for me was that CPACK_WIX_UPGRADE_GUID was never set in our project, so CMake was always generated a new one (there was a nice warning everyone ignored) and as a result, all installers look like they are referring a different application.

After setting CPACK_WIX_UPGRADE_GUID, installing previous versions automatically removes old packages.

But this doesn't work on packages which didn't have yet the CPACK_WIX_UPGRADE_GUID set.

Upvotes: 1

Related Questions