wixwindows-installerwix5

How to handle multiple exclusive components with files with identical names in Wix


I want to create an installer using Wix5. The software we want to install depends on another software and has some files which depend on which version of the prerequisite software is installed.

So let's say the installed software has Version1. I then want to install the files for Version1 only. If Version2 is installed the files for Version2 and so on.

However the files to be installed have the same name so I get an error: WIX0091 Duplicate File with identifier '...' found. Access modifiers (global, library, file, section) cannot prevent these conflicts. Ensure all your identifiers of a given type (Directory, File, etc.) are unique.

This is not unexpected since I do have files with identical names that would get installed to the same directory. In reality however this would never a problem since you select a version on install and only those files are actually installed. How do I best handle this?

One solution I came up with is creating a componentgroup for each version, install them all to a separate folder and then move them after installation into the correct folder. So the componentgroups would look like this

<ComponentGroup Id="basefilescomponent1" Directory="version1folder">
          <Files Include="..\..\..\Project.Version1\bin\$(Configuration)\**">
              <Exclude Files="..\..\..\Project.Version1\bin\$(Configuration)\*.pdb"></Exclude>
          </Files>
</ComponentGroup>
<ComponentGroup Id="basefilescomponent2" Directory="version2folder">
          <Files Include="..\..\..\Project.Version2\bin\$(Configuration)\**">
              <Exclude Files="..\..\..\Project.Version2\bin\$(Configuration)\*.pdb"></Exclude>
          </Files>
</ComponentGroup>

And then I move them via https://learn.microsoft.com/en-us/windows/win32/msi/movefiles-action or a CustomAction. This seems a bit "dirty" to me. More importantly though it also means that I have to manually deal with those files on uninstall or update. Another Idea would be a separate installer for each version but that also has its downsides. (mainly the need to always pass the correct installer to customers while currently the installer can check the version with a customaction itself) So I was wondering if there was another easier way.


Solution

  • You can't use the Files element in this case. Specify the individual files as File elements to give them unique Id attributes then use the Condition attribute to only install the right set of files at runtime.