1

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="&quot;%1&quot; &quot;1.0.0&quot;" 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="&quot;%1&quot; &quot;2.0.0&quot;" TargetFile="wpfFile"/>
                 </Extension>
               </ProgId>
             </Component> 
        </ComponentGroup>
    </Fragment>
</Wix>

Only difference is in the ProgId's Id w.r.t file association.

Erik
  • 503
  • 1
  • 7
  • 26
Sanketh P B
  • 394
  • 2
  • 16

1 Answers1

0

Change the file association(s) to include a version number as part of its caption: xyz1, xyz2, etc... Only do this if you want the products to be possible to install side-by-side. This avoids interference between your products. The alternative would be to register your file associations via a custom action run on uninstall that would look for your other installations. Very clunky and error prone if you ask me. Rule of thumb in my world: Always chose to rely on small changes in application and setup design to avoid custom solutions with added risk. If you can reliably avoid read/write custom actions that is always the right call for reliability and simplicity.

I prefer to avoid side-by-side installations since it is rare that two versions of a software are actively maintained. The exception might be major versions released to the public - in other words version 1, 2, 3 etc... I wouldn't mess with new associations per build to put it like that.

If you want to install side-by-side you must change all component guids for components that are installed side-by-side, and use proper merge modules or wix includes for shared files that aren't installed side-by-side (typically COM servers and the like that can only be installed once per-machine). This is in order for reference counting to work correctly. Perhaps this answer is worth a quick read: Change my component GUID in wix?. Or better yet, rely on automatic, generated guids as described in the linked post.

Perhaps also have a look at this:

Community
  • 1
  • 1
Stein Åsmul
  • 39,960
  • 25
  • 91
  • 164
  • xyz extension / file is a project file, so the user must be able to open the project in new version without having to perform additional operations. So is there any other way to retain associations? Parallel installation is supported and guid change etc is done as per WiX guidelines. – Sanketh P B May 02 '15 at 18:28
  • Try putting the file association elements in a wix include file so that it is reference counted properly (component in use by 2 setups). This needs to be implemented in both versions to work correctly, but then it should be left alone during uninstall of one of the products. If you do this right it is more reliable than other options. – Stein Åsmul May 02 '15 at 18:34
  • To be more precise: extract the parent component containing the file association and put it in a wix include file - (keep the hard coded guid for this purpose is my advice), and then include it in both your setups. – Stein Åsmul May 02 '15 at 18:38
  • If the file association is linked to an EXE file the former will not work if you need to link to two different versions of the EXE. Didn't visual studio use to "fix" this by implementing an intermediate version selector executable that would ask the user what version to use if both versions were available on the box? – Stein Åsmul May 03 '15 at 07:25