3

I've just updated our wix install scripts as per this previous question/answer How to implement WiX installer upgrade?. The idea was to prevent an older version 'downgrading' a newer version. So I have parts of the wix file that look like:

  <Product Id="A_GUID"
    <Upgrade Id="18626be5-521c-4b58-ab8a-54baddf66679">
      <UpgradeVersion
        Property="NEWERVERSIONDETECTED"
        Minimum="$(var.Version)"
        IncludeMinimum="no"
        OnlyDetect="yes"
        ExcludeLanguages="yes"        
        />
     </Upgrade>

     <CustomAction Id="NewerVersionFound" Error="Can't downgrade." />

     <InstallExecuteSequence>
       <Custom Action="NewerVersionFound"
             After="FindRelatedProducts">NEWERVERSIONDETECTED</Custom>
       <RemoveExistingProducts After="InstallInitialize" />
     </InstallExecuteSequence>

I have two versions of this, say 2.1 and 2.2. The current practice is to keep the Product Id Guid (shown as 'A_GUID' above) the same for minor versions (like 2.x) and only to change for major - so moving from 1.x to 2.x we change the Guid.

But, the above doesn't work if the Product Guid is kept the same for 2.1 and 2.2, despite the '$(var.Version)' changing. If I change the Guid, it does work (and prevents the downgrade 2.2 -> 2.1).

I was wondering why this is the case (assuming I'm doing it correctly) - why do we need two bits of information (guid and version) for this to work?

Edit1a: There is an UpgradeCode Guid in the wix, which stays the same for each version. Edit1b: If it's relevant, this is done with an old version of wix (2.x).

Community
  • 1
  • 1
PeteOopNorf
  • 97
  • 1
  • 7

1 Answers1

4

Its not related to the product guid.

It is always related to the UpgradeCode you are specify as attribute at the product node.

<Product Id="*" Name="name" Version="$(var.Version)" UpgradeCode="12345678-55F7-4731-A318-772EF75D2830">

Within the upgrade node you are looking to the upgradecode (and not to product guid). You can specify multiply Upgradecodes to find different versions of your software. but upgradecode should normally stay the same in a product. see best practices on MS homepage, please.

    <Upgrade Id="12345678-55F7-4731-A318-772EF75D2830">
        <UpgradeVersion ExcludeLanguages="no" Property="OLDVERSIONFOUND"   
            IgnoreRemoveFailure="yes" MigrateFeatures="no" IncludeMinimum="no"                
            Minimum="0.0.0.0" Maximum="$(var.Version)" IncludeMaximum="no"                
        />
        <UpgradeVersion OnlyDetect="yes" Property="NEWAPPFOUND" IncludeMinimum="yes" Minimum="$(var.Version)" Maximum="99.99.99.99" />
    </Upgrade>

With an custom action (you already have) you react on that.

 <CustomAction Id="OldAppFound" Error="Newer app of [ProductName] is installed" />

Ofcurse you need to schedule the tests for that in the sequences (you also did)

    <InstallExecuteSequence>
        <Custom Action="OldAppFound" After="FindRelatedProducts">NEWAPPFOUND</Custom>
    </InstallExecuteSequence>
    <InstallUISequence>
        <Custom Action="OldAppFound" After="FindRelatedProducts">NEWAPPFOUND</Custom>
    </InstallUISequence>

And if necessary remove the old one (you also have in your code)

    <InstallExecuteSequence>    
        <RemoveExistingProducts After="InstallInitialize" />
    </InstallExecuteSequence>
coding Bott
  • 4,287
  • 1
  • 27
  • 44
  • Bernd, thanks for the swift reply. I should have shown more of the wix code in my example, as I do have an UpgradeCode and it is the same for all versions. So, my code still allows downgrades with the UpgradeCode unless I change the Guid. I notice you've used 'Product Id="*"' in your example. Doesn't this automatically create new Guids for each version? – PeteOopNorf Apr 05 '13 at 09:40
  • @PeteOopNorf yes i always generate a new product guid. Yes, it is *not* best practice. i try avoid to get into small or minor updates. http://msdn.microsoft.com/en-us/library/windows/desktop/aa370579(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/windows/desktop/aa367574(v=vs.85).aspx simple reason i don't want to set "REINSTALLMODE=omus" at the installer and get rid of these "other version is installed" messages. but that's what i do, it should not required to change the product code. you only need to take care about version number and upgrade code. – coding Bott Apr 05 '13 at 09:50
  • 3
    It seems I'm trying to do something with a minor upgrade that's only available to major upgrades. According to http://msdn.microsoft.com/en-us/library/aa370840%28v=vs.85%29.aspx; "This procedure relies on the FindRelatedProducts Action, which only runs during a first-time installation... Because minor upgrades are performed using reinstallation, this procedure cannot be used to determine whether a minor upgrade package is attempting to downgrade an application." So, the use of FindRelatedProducts with the UpgradeVersion only works for major upgrades (i.e. Guid updates for Product Ids). – PeteOopNorf Apr 05 '13 at 11:59
  • 1
    @BerndOtt using Product="*" is a completely reasonable practice. It just means you've decided only to do major upgrades. That's completely reasonable. – Rob Mensching Apr 05 '13 at 13:33
  • 1
    @PeteOopNorf that is correct. The solution described above only works for major upgrades. Minor upgrades would have to do something completely custom. – Rob Mensching Apr 05 '13 at 13:35