1

I'm developing a Windows Service installer using Wix. From what I understand, I should generate a unique Product ID for every Version of the service. This can be easily done by setting "*" in the Product Id attribute. However, when I do this and I rebuild the installer, it generated a different guid for every build. When I already have any version of service installed on my machine, this causes several problems: i.e. 'exe' file remaining after uninstall process being finished, multiple entires in Programs in Control Panel.

After some investigation, I found that the solution to this would be to update the Product Id manually every time when version number of the service would change. Or maybe I am missing something?

Anyway, the question is: is there any way to make this process automated, so that the guid would be same every time I build the same version of the service but change only when the version is updated? Any external tool for Wix?

PJDev
  • 951
  • 5
  • 20
  • [List of common major upgrade problems](https://stackoverflow.com/questions/56989906/wix-does-not-uninstall-older-version/56991527#56991527). – Stein Åsmul Jan 14 '20 at 11:04

1 Answers1

2

Build Automation: You can use build automation in a number of ways to automate the creation of new product GUIDs and similar. You would pass in values to the WiX project file and such things, but perhaps that is not what you want to maintain. Let me add another option below.


Major Upgrade Element: I assume you have a major upgrade element in there? It takes care of uninstalling the previous version if configured correctly. Typically you see multiple versions in Add / Remove Programs when you re-build the same version and install on top of the last installation.

Suggestion: You can manually configure the Upgrade table to uninstall "same version installations". You take out the "auto-magic" of the "MajorUpgrade" element and do things yourself with Upgrade elements (an older way to configure the Upgrade table that yields more detailed control):

Remove this (or just comment it out):

<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />

Add this:

<!-- The top of your new source - compiler variables, can be overridden at compile time via candle.exe and light.exe switches -->
<?xml version="1.0" encoding="UTF-8"?>
<?define MyProductVersion = "2.0.0.0" ?>

<!-- Sample GUID only, do not use in your package  ->
<?define MyUpgradeCode = "88888888-7777-7777-7777-888888888888" ?> 

<..>

<Upgrade Id="$(var.MyUpgradeCode)">
  <UpgradeVersion Minimum="$(var.MyProductVersion)" OnlyDetect="yes" IncludeMinimum="yes" Property="DOWNGRADE_DETECTED"  />
  <UpgradeVersion Property="PRODUCTLINE1" IncludeMinimum="yes" IncludeMaximum="yes" Maximum="$(var.MyProductVersion)" Minimum="0.0.0"  />
</Upgrade>

<..>

<!-- You have to add RemoveExistingProducts to the InstallExecuteSequence table -->
<InstallExecuteSequence>
  <!-- Potential scheduling (after): InstallValidate, InstallInitialize, InstallExecute, InstallExecuteAgain, InstallFinalize -->
  <RemoveExistingProducts After="InstallInitialize" />
</InstallExecuteSequence>

Summary: The above should let you rebuild your setup and install any number of times using the same version number and the installation process will remove prior installation "auto-magically". Please test. No guarantees. Murphy's law. Etc... :-).


Some Links:

Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • 1
    Thanks for such a detailed answer and all the links. Such a great read which clarified many things about the Wix installer. And Upgrade element indeed seems to fix the issues I was struggling with :) – PJDev Jan 14 '20 at 22:32