How to implement WiX installer upgrade?

后端 未结 12 1293
礼貌的吻别
礼貌的吻别 2020-11-22 07:05

At work we use WiX for building installation packages. We want that installation of product X would result in uninstall of the previous version of that product on that machi

相关标签:
12条回答
  • 2020-11-22 07:22

    This is what worked for me, even with major DOWN grade:

    <Wix ...>
      <Product ...>
        <Property Id="REINSTALLMODE" Value="amus" />
        <MajorUpgrade AllowDowngrades="yes" />
    
    0 讨论(0)
  • 2020-11-22 07:25

    You might be better asking this on the WiX-users mailing list.

    WiX is best used with a firm understanding of what Windows Installer is doing. You might consider getting "The Definitive Guide to Windows Installer".

    The action that removes an existing product is the RemoveExistingProducts action. Because the consequences of what it does depends on where it's scheduled - namely, whether a failure causes the old product to be reinstalled, and whether unchanged files are copied again - you have to schedule it yourself.

    RemoveExistingProducts processes <Upgrade> elements in the current installation, matching the @Id attribute to the UpgradeCode (specified in the <Product> element) of all the installed products on the system. The UpgradeCode defines a family of related products. Any products which have this UpgradeCode, whose versions fall into the range specified, and where the UpgradeVersion/@OnlyDetect attribute is no (or is omitted), will be removed.

    The documentation for RemoveExistingProducts mentions setting the UPGRADINGPRODUCTCODE property. It means that the uninstall process for the product being removed receives that property, whose value is the Product/@Id for the product being installed.

    If your original installation did not include an UpgradeCode, you will not be able to use this feature.

    0 讨论(0)
  • 2020-11-22 07:27

    I would suggest having a look at Alex Shevchuk's tutorial. He explains "major upgrade" through WiX with a good hands-on example at From MSI to WiX, Part 8 - Major Upgrade.

    0 讨论(0)
  • 2020-11-22 07:31

    The Upgrade element inside the Product element, combined with proper scheduling of the action will perform the uninstall you're after. Be sure to list the upgrade codes of all the products you want to remove.

    <Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
    <Upgrade Id="00000000-0000-0000-0000-000000000000">
      <UpgradeVersion Minimum="1.0.0.0" Maximum="1.0.5.0" Property="PREVIOUSVERSIONSINSTALLED" IncludeMinimum="yes" IncludeMaximum="no" />
    </Upgrade>
    

    Note that, if you're careful with your builds, you can prevent people from accidentally installing an older version of your product over a newer one. That's what the Maximum field is for. When we build installers, we set UpgradeVersion Maximum to the version being built, but IncludeMaximum="no" to prevent this scenario.

    You have choices regarding the scheduling of RemoveExistingProducts. I prefer scheduling it after InstallFinalize (rather than after InstallInitialize as others have recommended):

    <InstallExecuteSequence>
      <RemoveExistingProducts After="InstallFinalize"></RemoveExistingProducts>
    </InstallExecuteSequence>
    

    This leaves the previous version of the product installed until after the new files and registry keys are copied. This lets me migrate data from the old version to the new (for example, you've switched storage of user preferences from the registry to an XML file, but you want to be polite and migrate their settings). This migration is done in a deferred custom action just before InstallFinalize.

    Another benefit is efficiency: if there are unchanged files, Windows Installer doesn't bother copying them again when you schedule after InstallFinalize. If you schedule after InstallInitialize, the previous version is completely removed first, and then the new version is installed. This results in unnecessary deletion and recopying of files.

    For other scheduling options, see the RemoveExistingProducts help topic in MSDN. This week, the link is: http://msdn.microsoft.com/en-us/library/aa371197.aspx

    0 讨论(0)
  • 2020-11-22 07:34

    Finally I found a solution - I'm posting it here for other people who might have the same problem (all 5 of you):

    • Change the product ID to *
    • Under product add The following:

      <Property Id="PREVIOUSVERSIONSINSTALLED" Secure="yes" />
      <Upgrade Id="YOUR_GUID">  
         <UpgradeVersion
            Minimum="1.0.0.0" Maximum="99.0.0.0"
            Property="PREVIOUSVERSIONSINSTALLED"
            IncludeMinimum="yes" IncludeMaximum="no" />
      </Upgrade> 
      
    • Under InstallExecuteSequence add:

      <RemoveExistingProducts Before="InstallInitialize" /> 
      

    From now on whenever I install the product it removed previous installed versions.

    Note: replace upgrade Id with your own GUID

    0 讨论(0)
  • 2020-11-22 07:35

    In the newest versions (from the 3.5.1315.0 beta), you can use the MajorUpgrade element instead of using your own.

    For example, we use this code to do automatic upgrades. It prevents downgrades, giving a localised error message, and also prevents upgrading an already existing identical version (i.e. only lower versions are upgraded):

    <MajorUpgrade
        AllowDowngrades="no" DowngradeErrorMessage="!(loc.NewerVersionInstalled)"
        AllowSameVersionUpgrades="no"
        />
    
    0 讨论(0)
提交回复
热议问题