Search code examples
wixwindows-installerwixsharp

Creating a dynamic install directory in WiXSharp


I am having trouble with with my directories, I want my InstallDir to be my top parent directory and for any other Dir to be contained within this folder structure. I have tried this multiple ways and can't seem to work it out but what I am aiming for is to be able to use the installDirDialog to change the install location. The directory left unchanged installs correctly, but if i was to change the install location it only builds the new folder structure and the files install install to the default location. I know why it's installing to this location because its referencing a static string, I only used the below as an example to simplify the problem I am having.

string dirs = @"%ProgramFiles%\My Company\My Product";
var project = new ManagedProject("MyProduct",
   new InstallDir(dirs),        
   new Dir(dirs + @"\DataAPI",
       new Files(@"E:\Temp\installertemp\DataAPI\*.*"))); 

Another approach was to use an MSI property and set that as the install path.

public class General
    {
        public static string Product = "PRODUCT";
        public static string InstallLocation = "INSTALLDIRECTORY";
    }

In setup.cs string dirs = General.InstallLocation;

I then set this property in the install dialog. MsiRuntime.Session[General.InstallLocation] = installDir.Text;

This didn't work either and only passed INSTALLDIRECTORY as the path.


Solution

  • After countless hours wasted the solution was actually very simple and made clear to me by the kind folks over at Wixsharp.

    Simply move the end bracket of instalDir to include any children Dirs and their files.

     new InstallDir(dirs,        
       new Dir("DataAPI",
           new Files(@"E:\Temp\installertemp\DataAPI\*.*")));