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

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

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

58345 次浏览

您需要使用升级表:

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

这是一个教程

我检查了上面提到的所有职位和 还是花了很长时间试图让这个工作。

步骤3中 升级的官方指导方针上的 提示帮助很大: 您需要一个新的 Product/@Id来禁用消息“本产品的另一个版本已经安装”。

我使用了这个升级部分(Product 的子节) :

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

请注意,OnlyDetect被设置为“ no”。如果您有以下部分(Product 的子节) ,这将触发删除旧版本:

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

还要注意,显然,只有版本号的前三个组件被用来检查升级..。

只要把这个元素放在 Product元素下面:

<MajorUpgrade AllowDowngrades="yes" />

更多信息在 这个如何

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

  1. 确保每次生成时产品 ID 都会更改。如果不这样做,您总是会收到 OP 提到的“已经安装”消息。

    <Product Id="*" ...>
    
  2. 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)" />
    
  3. Keep your UpgradeCode constant (e.g.):

    <Product UpgradeCode="f4d7f199-28f6-45d5-ad99-7c62938274be" ...>
    
  4. 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." />
    

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>

我试过了,很管用。

  1. 把你的产品标签像这样写:

    产品 ID = “ *”名称 = “ Something”Language = “1033”Version = “1.0.0.0.0”Manufacturers = “ Someone”UpgradeCode = “43ab28d7-6681-4a05-a6b5-f980733aeeed”

ProductId 应该设置为 * ,这样每次构建项目时,它都会使用不同的 Id。

  1. 在 Package 元素中嵌套一个 MajorUpgrade 标记,其外观如下:

    MajorUpgrade 允许降级 = “ no”DowngradeErrorMessage = “已经安装了[ ProductName ]的更新版本。”

因此,每次您更新您的版本(或您的版本是相同的,不少于当前版本) ,它重新安装您的产品通过删除以前的文件和安装产品文件。 它将 不是降级你的产品。