Search code examples
.netvisual-studio-2010interopwindows-installertlbimp

Can Windows installer deploy an assembly based on the version of an external application?


I am developing a small program (a dll) in Visual Studio 2010 / .NET 4 that integrates with an external application (we'll call it ExApp) through COM interop. I am generating the interop assemblies myself using TlbImp.exe, as none are provided by the external application. ExApp comes in three popular versions, each with an effectively identical API, but each having a different (and incompatible) generated interop dll. At the moment, that means I have three separate installers:

  • Installer w/ my.dll built/linked against Interop.ExApp.dll v1
  • Installer w/ my.dll built/linked against Interop.ExApp.dll v2
  • Installer w/ my.dll built/linked against Interop.ExApp.dll v3

There must be a better solution than this.

How do I configure Visual Studio / Windows Installer so that I only need one install .exe? Meaning that the installer will detect the version of ExApp, and install the corresponding versions of my.dll and Interop.ExApp.dll.

And a bonus question: Since the ExApp API has not meaningfully changed, how can I compile one version of my.dll to work with any installed version of ExApp?


Solution

  • Why don't you build the interops with 3 different file names and then create a factory pattern in your application to decide which provider to use at runtime?

    I could show you ways of searching the system to install one of 3 mutually exclusive files but I don't think that kind of complexity belongs in the installer. And it would fall apart anyways if someone upgraded the application that you are creating the interop for.