I have Product A with Versions 1.0.0 and V2.0.0 each associated with file type xyz (to executable product.exe) using WiX File association. When Product A V1.0.0 is installed, then file extension xyz is associated. Next, I install Product A V2.0.0, now the file xyz is associated with Product A V2.0.0. File association is overridden as expected or vice-versa if 2.0.0 is installed first and later V1.0.0.
If I uninstall V2.0.0 then the file association is removed for 2.0.0 and association of V1.0.0 is not restored and vice-versa.
How do I get the the file association restored for previous version automatically using WiX? Please see my WiX code below and suggest any possible corrections.
Product A V1.0.0 WiX 3.8 code:
<?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>
Product A V2.0.0 WiX 3.8 code:
<?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>
Only difference is in the ProgId's Id w.r.t file association.