我有版本 1.0.0 和 V2.0.0 的产品 A,每个版本都使用 WiX 文件关联与文件类型 xyz(到可执行 product.exe)相关联。安装产品 A V1.0.0 时,会关联文件扩展名 xyz。接下来,我安装 Product A V2.0.0,现在文件 xyz 与 Product A V2.0.0 相关联。如果首先安装 2.0.0 和更高版本的 V1.0.0,文件关联将按预期覆盖,反之亦然。
如果我卸载 V2.0.0,则删除 2.0.0 的文件关联,并且不会恢复 V1.0.0 的关联,反之亦然。
如何使用 WiX 自动恢复以前版本的文件关联?请在下面查看我的 WiX 代码并提出任何可能的更正建议。
产品 A V1.0.0 WiX 3.8 代码:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="PUT-GUID-HERE" Name="Product A 1.0" Language="1033" Version="1.0.0.0" Manufacturer="Microsoft" UpgradeCode="PUT-GUID-HERE">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="Product A 1.0" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Product A 1.0" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="ProductComponent" Guid="PUT-GUID-HERE">
<File Id="openBox" Source="D:\open-box.ico" />
<File Id="wpfFile" Source="D:\product.exe" />
<ProgId Advertise="no" Description="My WPF File" Icon="openBox" Id="xyzFileAssociation_1_0">
<Extension Id="xyz" ContentType="application/xyz">
<Verb Id="open" Command="open with my app" Argument=""%1" "1.0.0"" TargetFile="wpfFile"/>
</Extension>
</ProgId>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
产品 A V2.0.0 WiX 3.8 代码:
<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
<Product Id="PUT-GUID-HERE" Name="Product A 2.0" Language="1033" Version="2.0.0.0" Manufacturer="Microsoft" UpgradeCode="PUT-GUID-HERE">
<Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />
<MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
<MediaTemplate />
<Feature Id="ProductFeature" Title="Product A 2.0" Level="1">
<ComponentGroupRef Id="ProductComponents" />
</Feature>
</Product>
<Fragment>
<Directory Id="TARGETDIR" Name="SourceDir">
<Directory Id="ProgramFilesFolder">
<Directory Id="INSTALLFOLDER" Name="Product A 2.0" />
</Directory>
</Directory>
</Fragment>
<Fragment>
<ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
<!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
<Component Id="ProductComponent" Guid="PUT-GUID-HERE">
<File Id="openBox" Source="D:\open-box.ico" />
<File Id="wpfFile" Source="D:\product.exe" />
<ProgId Advertise="no" Description="My WPF File" Icon="openBox" Id="xyzFileAssociation_2_0">
<Extension Id="xyz" ContentType="application/xyz">
<Verb Id="open" Command="open with my app" Argument=""%1" "2.0.0"" TargetFile="wpfFile"/>
</Extension>
</ProgId>
</Component>
</ComponentGroup>
</Fragment>
</Wix>
唯一的区别在于 ProgId 的 Id wrt 文件关联。