如何让 Wix 更新以前安装的程序版本 [英] How to get Wix to update a previously installed version of a program

查看:15
本文介绍了如何让 Wix 更新以前安装的程序版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用 Wix 编写了一个安装程序,它可以很好地安装我的程序.现在我需要更新它,所以我提高了版本号,但是当我在旧程序上安装新程序时,它抱怨已经安装了旧版本并告诉我先卸载它.

I wrote an install program with Wix and it worked fine to install my program. Now I need to update it, so I bumped up the version number but when I go to install the new program over the old one it complains that an older version is already installed and tells me to uninstall it first.

如何在重新安装之前更新或自动卸载它?

How do I get it to update or automatically uninstall it before reinstalling?

推荐答案

我觉得提供的答案都不是完整的或独立的,所以在我挖过这个沼泽之后,这是我认为有必要得到的步骤更新工作的(完全不言而喻的)要求:

I feel that none of the provided answers are complete or self-contained, so after digging my way through this swamp, here's the steps I think are necessary to get the (utterly self-evident) requirement of an update to work:

  1. 确保每次构建时您的产品 ID 都会更改.如果不这样做,您将始终收到 OP 提到的已安装"消息.

  1. Make sure your Product Id changes every time you build. If you don't, you'll always get the "already installed" message the OP mentioned.

<Product Id="*" ...>

  • 每次产品本身发生变化时,都要更改产品版本.我想最好的选择是将它绑定到一个程序集版本(它也应该是自动递增的),但当然你也可以手动更改它.如果您在第 4 点中使用 AllowSameVersionUpgrades 属性,则此步骤不是严格要求的,但我敢说,在任何情况下保持产品版本不变都是不好的做法.

  • Change the Product Version every time the product itself changes. I suppose the best option is to bind it to an assembly version (which should be auto-incremented as well), but of course you could also just change it manually. This step is not strictly required if you use the AllowSameVersionUpgrades attribute in point 4, but I'd venture to say that keeping your product version constant is bad practise in any case.

    <Product Version="!(bind.FileVersion.MyAssemblyDll)" ...>
    <File Id="MyAssemblyDll" Name="$(var.001_Application.MyAssembly.TargetFileName)" Source="$(var.001_Application.MyAssembly.TargetPath)" />
    

  • 保持 UpgradeCode 不变(例如):

  • Keep your UpgradeCode constant (e.g.):

    <Product UpgradeCode="f4d7f199-28f6-45d5-ad99-7c62938274be" ...>
    

  • 添加 MajorUpgrade 元素(来自 Wix 3.5.1315.0).要绕过 MajorUpgrade 将忽略产品版本的修订号更改的问题,请添加 AllowSameVersionUpgrades(或者如果您更喜欢 AllowDowngrades)属性.这样,您将能够从例如升级.1.0.0.71.0.0.8.而不仅仅是从 1.0.7.01.0.8.0.如果您不这样做,您可能会在程序和功能"中看到多个安装.

  • Add the MajorUpgrade element (from Wix 3.5.1315.0). To circumnavigate the catch that the MajorUpgrade will disregard changes in the revision number of the product version, add the AllowSameVersionUpgrades (or if you prefer AllowDowngrades) attribute. This way, you will be able to upgrade from e.g. 1.0.0.7 to 1.0.0.8. and not just from 1.0.7.0 to 1.0.8.0. If you don't do this, you may see multiple installations in Programs and Features.

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

  • 这是我的整个 .wix 文件(相关部分,导致用于产品绑定的程序集的两个片段大多是可选的,为了说明,任何可以获得程序集的方法都可以):

    Here's my whole .wix file (relevant parts, the two fragments that lead to the assembly which is used for product binding are mostly optional and for illustration, any way you can get a hold of the assembly will work):

    <?xml version="1.0" encoding="UTF-8"?>
    <?define ProductVersion="!(bind.FileVersion.MyAssemblyDll)"?>
    <?define UpgradeCode="f4d7f199-28f6-45d5-ad99-7c62938274be"?>
    
    <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:netfx="http://schemas.microsoft.com/wix/NetFxExtension">
      <Product
        Id="*"
        Name="My Product's name"
        Language="1033"
        Version="$(var.ProductVersion)"
        Manufacturer="My company"
        UpgradeCode="$(var.UpgradeCode)"
        Codepage="1252">
    
        <Package
          InstallerVersion="200"
          Compressed="yes"
          InstallScope="perUser"
          Description="My product description"
          Manufacturer="My company"
          Languages="1033"
          SummaryCodepage="1252"
          InstallPrivileges="limited" />
    
        <MajorUpgrade AllowSameVersionUpgrades="yes" 
                      DowngradeErrorMessage="A newer version of [ProductName] is already installed. If you are sure you want to downgrade, remove the existing installation via Programs and Features." />
    
      </Product>
    
      <Fragment>
        <Directory Id="TARGETDIR" Name="SourceDir">
          <Directory Id="LocalAppDataFolder">
            <Directory Id="INSTALLFOLDER" Name="My Install Dir" >
              <Component Id="INSTALLFOLDER" Guid="f6ba8a12-6493-4911-8edd-dce90e1d8e8b" >
                <RemoveFolder On="both" Id="INSTALLFOLDER"/>
                <RegistryValue Root="HKCU" Key="Software[Manufacturer][ProductName]" Type="string" Value="My Registry value" />
              </Component>
            </Directory>
          </Directory>
        </Directory>
      </Fragment>
    
      <Fragment>
        <ComponentGroup Id="ProductComponents" >
          <Component Id="ProductComponent" Guid="1939f0f5-19f6-498b-bf95-8f1c81501294" DiskId="1" Directory="INSTALLFOLDER" >
            <File Id="MyAssemblyDll" Name="$(var.001_MyApplication.MyAssembly.TargetFileName)" Source="$(var.001_MyApplication.MyAssembly.TargetPath)" />
          </Component>
        </ComponentGroup>
      </Fragment>
    </Wix>
    

    这篇关于如何让 Wix 更新以前安装的程序版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆