如何让Wix更新以前安装的程序版本

时间:2009-02-01 12:14:23

标签: wix install

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

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

5 个答案:

答案 0 :(得分:86)

我觉得所提供的答案都不是完整的或自包含的,所以在深入了解这个沼泽之后,我认为必须采取的步骤才能获得更新工作(完全不言而喻)的要求:

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

    <Product Id="*" ...>
    
  2. 每次产品本身更改时更改产品版本。我想最好的选择是将它绑定到一个程序集版本(也应该自动增加),但当然你也可以手动更改它。如果您在第4点使用AllowSameVersionUpgrades属性,则不严格要求此步骤,但我冒昧地说,保持产品版本不变是任何情况下都不好的做法。

    <Product Version="!(bind.FileVersion.MyAssemblyDll)" ...>
    <File Id="MyAssemblyDll" Name="$(var.001_Application.MyAssembly.TargetFileName)" Source="$(var.001_Application.MyAssembly.TargetPath)" />
    
  3. 保持您的UpgradeCode不变(例如):

    <Product UpgradeCode="f4d7f199-28f6-45d5-ad99-7c62938274be" ...>
    
  4. 添加MajorUpgrade元素(来自Wix 3.5.1315.0)。要绕过MajorUpgrade忽略产品版本修订号更改的捕获,请添加AllowSameVersionUpgrades(或者如果您更喜欢AllowDowngrades)属性。这样,您就可以从例如1.0.0.71.0.0.8。而不只是从1.0.7.01.0.8.0。如果不这样做,您可能会在“程序和功能”中看到多个安装。

    <MajorUpgrade AllowSameVersionUpgrades="yes" DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
    
  5. 这是我的整个.wix文件(相关部分,导致用于产品绑定的程序集的两个片段大多是可选的,为了说明,任何方式你都可以使用程序集):

    <?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>
    

答案 1 :(得分:38)

我查看了上面提到的所有帖子,并且仍然花了很多时间试图让它发挥作用。

步骤3中official HOWTO for upgrades上的提示有很多帮助:您需要一个新的Product/@Id来禁用“此产品的另一个版本已安装”的消息。

我使用了此升级部分(Product of child):

<Upgrade Id="$(var.UpgradeCode)">
  <UpgradeVersion Minimum="1.0.0"
                  IncludeMinimum="yes"
                  OnlyDetect="no"
                  Maximum="$(var.Version)"
                  IncludeMaximum="no"
                  Property="PREVIOUSFOUND" />
</Upgrade>

请注意,OnlyDetect设置为“否”。如果您有以下部分(产品的子代),则会触发删除旧版本:

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

另请注意,显然,只有版本号的前三个组件用于检查升级......

答案 2 :(得分:7)

您需要使用升级表:

<Upgrade Id='15E2DAFB-35C5-4043-974B-0E342C25D76A'>
    <UpgradeVersion Property='OLDVERSIONFOUND' IncludeMinimum='no' Minimum='0.0.0.0' />
</Upgrade>

您还需要添加操作:

<InstallExecuteSequence>
    <LaunchConditions After='AppSearch' />
    <RemoveExistingProducts After='InstallValidate' />
</InstallExecuteSequence>

Here is a tutorial

答案 3 :(得分:3)

我尝试了这个,它对我有用。

  1. 将您的商品标签放置如下:
      

    产品ID =&#34; *&#34;名称=&#34;东西&#34;语言=&#34; 1033&#34;版本=&#34; 1.0.0.0&#34;制造商=&#34;有人&#34;的UpgradeCode =&#34; 43ab28d7-6681-4a05-a6b5-f980733aeeed&#34;

  2. 产品ID应设置为*,以便每次构建项目时,都需要不同的ID。

    1. 在您的Package元素中嵌入一个MajorUpgrade标记,如下所示:
        

      MajorUpgrade AllowDowngrades =&#34; no&#34; DowngradeErrorMessage =&#34;已安装较新版本的[ProductName]。&#34; AllowSameVersionUpgrades =&#34;是&#34; /

    2. 因此,每次更新版本(或版本相同,不低于当前版本)时,都会通过删除以前的文件并安装产品文件来重新安装产品。 不会降级您的产品。

答案 4 :(得分:-4)

只需将此元素放在Product元素下:

<MajorUpgrade AllowDowngrades="yes" />

this HowTo

中的更多信息
相关问题