我已经编写并维护了许多 Wix 安装源文件,我使用这些文件来构建 MSI 文件以分发我的应用程序。
我没有明确地为任何类型的升级、更新、重新安装或任何类似的事情进行编程——有一个功能由许多具有稳定 GUID 的组件组成,并且我观察到至少干净的安装确实如此我所期望的。
但是,我(以及拥有我分发的 MSI 文件的任何人)似乎可能使用各自的(不同的)MSI 文件并排安装我的应用程序的不同版本。这本身不是问题,除了我显然使用与安装目标相同的文件夹——“%ProgramFiles(x86)%\Foobar”——来安装应用程序(无论版本如何)。这意味着实际上有始终只有一个最终安装的版本。
我认为 Windows Installer 到目前为止的行为是正确的,它从最后安装的 MSI 软件包中更新文件。这样做的一个有趣的副作用是,如果最后一个 MSI 是早期版本,则应用程序文件夹中的文件将被该早期版本的副本覆盖。
但对我来说,这些似乎都不是真正的问题。我想修复实际安装的内容(单个应用程序版本)与 Windows 跟踪的安装内容之间的差异 - 在我的例子中是两个不同应用程序版本的两条记录。
由于我将应用程序安装在不依赖于所安装版本的文件夹中,因此通过 Windows 跟踪多个应用程序版本是一个错误。
所以我想我的问题是,如何解决这个问题,以便只显示一个版本(反射(reflect)现实),或者在这种情况下惯用的方法是什么?我故意没有过度指定我的 Wix 源代码,希望 Windows Installer 能够使用一些内置智能来自行解决所有问题。但我想我可能需要添加一些明确的升级或卸载先前版本优先指令。
我的缩小版 Wix 源代码(文件“foobar.wxs”)如下所示:
<?xml version="1.0" encoding="utf-8" ?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util="http://schemas.microsoft.com/wix/UtilExtension">
<Product Name="Foobar" Manufacturer="ACME Inc." Id="*" UpgradeCode="ae9a7d6d-6c2d-446a-97d9-9dbe829d2ea8" Language="1033" Codepage="1252" Version="!(wix.PRODUCT_VERSION)">
<Package Id="*" Languages="1033" SummaryCodepage="1252" Compressed="yes" InstallerVersion="200" />
<Icon Id="foobar" SourceFile="!(wix.APPPATH)/foobar.ico" />
<Property Id="ARPPRODUCTICON" Value="foobar" />
<Property Id="ARPCOMMENTS" Value="Gives you full foobar powers" />
<MediaTemplate EmbedCab="yes" CompressionLevel="high" />
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="DesktopFolder" />
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLDIR" Name="Foobar" FileSource="!(wix.APPPATH)">
<Component>
<File Id="foobar.exe" Name="foobar.exe" />
</Component>
<!-- There are other components like above (assets) -->
</Directory>
</Directory>
<Directory Id="ProgramMenuFolder">
<Directory Id="foobar_menu" Name="Foobar">
<Component Id="foobar_shortcut" Guid="e80a6b95-a145-453a-b327-65a977e741fe">
<Shortcut Icon="foobar" Id="foobar_shortcut" Name="Foobar" Target="[foobar]foobar.exe" />
<Shortcut Directory="DesktopFolder" Icon="foobar" Id="foobar_desktop_shortcut" Name="Foobar" Target="[foobar]foobar.exe" />
<RegistryValue KeyPath="yes" Root="HKMU" Key="Software\[Manufacturer]\[ProductName]" Type="string" Value="" />
<RemoveFolder Id="remove_foobar_menu" On="uninstall" />
</Component>
</Directory>
</Directory>
<Directory Id="CommonAppDataFolder">
<Directory Id="app_data_foobar" Name="foobar">
<Component Guid="" Id="app_data_config_folder">
<CreateFolder />
</Component>
<Component Guid="" Id="app_data_config_folder_log_file">
<File Name="foobar.log" Source="foobar.log.template">
<!-- Add write access permission to the log file to members of "Users" group. -->
<!-- PermissionEx Sddl="D:AR(A;;GWGR;;;BU)" / -->
<!-- Bug with Windows Installer, can't use PermissionEx/MsiLockPermissionsEx table. See https://stackoverflow.com/questions/55145282/how-to-include-inherited-permissions-when-specifying-permissions-for-a-file-inst -->
<util:PermissionEx Append="yes" GenericWrite="yes" User="Users" />
</File>
</Component>
</Directory>
</Directory>
</Directory>
<Feature Id="foobar">
<ComponentGroupRef Id="foobar" />
<ComponentRef Id="foobar_shortcut" />
<ComponentRef Id="app_data_config_folder" />
<ComponentRef Id="app_data_config_folder_log_file" />
</Feature>
</Product>
</Wix>
我正在使用以下 Windows 命令提示符行编译目标文件:
candle.exe -ext WixUtilExtension -out %TEMP% foobar.wxs
然后生成 MSI 文件:
light.exe -ext WixUtilExtension -spdb "-dAPPPATH=%apppath%" "-dPRODUCT_VERSION=%version%" -out %TEMP%\foobar-%version%.msi %TEMP%\foobar.wixobj
(使用 Wix 3.11.1.2318)
最佳答案
升级代码:只要您设置了升级代码(用于标识一系列相关产品),您就可以使用主要升级元素来指示正在升级的产品。将作为新 MSI 安装的一部分进行卸载。
MajorUpgrade 元素:只需注入(inject) MajorUpgrade element用于默认处理现有 WiX 源的主要升级。它是一种“神奇元素”,可以帮助您做出许多(通常是好的)假设。有更旧且更灵活的方法可以做到这一点 - 如果您需要更详细的控制(通常出于遗留目的 - 自动魔法并不涵盖所有基础):
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
以上是在 Visual Studio 中创建的所有 WiX 文件的标准用法。
Note: I will try to tune up this answer shortly with more links, but give that a go first?
第一个链接:Using Visual Studio to make WiX files. The Hello WiX and Visual Studio-type of scenario .
主要升级建议阅读:有关主要升级的一些知识。所有 WiX 标记本质上都围绕编译的 MSI Upgrade table 。在那里配置了主要的升级逻辑。自定义操作也可能会影响其他一些事情,例如启动条件。
- WiX 文档:How To: Implement a Major Upgrade In Your Installer
- 主要升级 -
常见问题
:WIX does not uninstall older version - 主要升级 -
手动配置
:Adding entries to MSI UpgradeTable to remove related products (使用旧式升级元素)
进一步:
关于wix - 如何避免使用 Windows Installer/MSI 安装产品的两个版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58935039/