multiple instances of same program

Mar 21, 2015 at 10:53 PM
Edited Mar 22, 2015 at 8:35 AM
I have a requirement, to allow installing multiple instances of the same program.

The instance name I will acquire from custom UI.

How can I set the installdir according to the choosen instance?
E.g. instance is "MyFirstInstance"
Installdir should be c:\program files\company\productMyFirstInstance

I should also be able to execute upgrade for any choosen instance.

The number of instances and also instance names, are not predefined!
Mar 22, 2015 at 8:48 AM
Strictly speaking it is not exactly a Wix# or even WiX question but a MSI one. The name of the program as it appears in the control panel depends on the product name and product ID (GUID) as it is stored in the corresponding table of the MSI file. These vaues are not dynamic. They are written during building the msi file. Thus you cannot change it during runtime (deploytime). Saying that there are some techniques which allow you to patch some MSI tables of the existing file. You possibly can use this technique.

The dynamic installdir is not a problem but because you need to install "multiple instances" this is where is the real challenge.
Mar 22, 2015 at 10:40 AM
I've look at InstanceTransforms, which could help with multipleinstances, though then the instancenames are predefined.
Ok, apart from solving variable number of instances,I need to set the folder name depending on the instanceid.

So if I want to install in %ProgramFiles%\Company\ProductName[INSTANCEID], how would I write the code in wix# to change the name of the folder ?
Suppose I have a property INSTANCEID or INSTANCENAME, how can I set the foldername where to install ?
var programDir = new Dir( serviceFeature, "%ProgramFiles%",
   new Dir("Company",
       new Dir(new Id("MYINSTALLDIR"),"MYINSTALLDIR",
            ... // list of files

Actions = new WixSharp.Action[] 
    new SetPropertyAction(new Id("SetMyInstallDirAction","MYINSTALLDIR", "ProductName[INSTANCEID]", ... )
Doesn't seem to work. but I'm completely new at WixSharp, probably I'm missing something essential.
If I try installing, with transform :FirstInstance, I get an error at install, could not access network location ProductNameFirstInstance
Mar 22, 2015 at 11:15 AM
OK, I think I misunderstood your original email. Let's start it again.

InstanceTransforms has no direct equivalent in Wix# but it can be easily handled via XML injection (you will wind the sample illustrating the technique). There is also a sample of setting the installdir.

Saying that, I am not familiar with InstanceTransforms so let me some time to see what is the best way of dealing with it withing Wix# domain.
Mar 22, 2015 at 11:29 AM
I managed to set the installation directory, it must be set to an absolute path (I was thinking it would be relative to programfiles\company).
I use a managed custom action for now to set it, using Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86).
Maybe there is a better way to accomplish this.
Transforms are added using the WixSourceGenerated event, using the example from this article
You have to start installer with msiexec /i MultiInstance.msi MSINEWINSTANCE=1 TRANSFORMS=":I01"
for a specific instance to install (I01 being the instanceID)
Uninstalling also seems to uninstall the specific instance (for each instance there is an entry in Programs and Features).
Variable number of instances seems to be rather impossible for now, as the transforms have to be present in the MSI installer.
Mar 22, 2015 at 11:46 AM
Edited Mar 23, 2015 at 12:09 AM
Great. This is in fact the direction I would be trying to solve it.

If you are OK with this you can simplify your code to the "Hello World" level and send it to me for including it in the official Wix# samples.
Mar 23, 2015 at 2:08 AM
OK. The sample has been added ( Samples/MultipleInstances Install/setup.cs)

Thank you for sharing.