How to install files in a folder based on custom property

Mar 8, 2016 at 12:18 PM
I have a ManagedProject that installs some files in %ProgramFiles%\Company\AppName.
Then I have some files that has to go into a folder that is resolved by reading a registry value.
How can that be done?

I can read the registry value using the Load method, but I guess I have to set a custom property there that I use for "new Dir", but I cannot figure out on how to do it.
Any suggestions?

Best regards
Mar 9, 2016 at 6:40 AM
Yes you have to read the reg value and set it to the INSTALLDIR property. Doing this you will mimic passing this property value from command line.

Though ManagedProject.Load event is not good because it is called after the UI is initialized. You will need to set this property from ManagedProject.UILoaded event for ManagedUI. And for the native MSI UI it has to be a custom action scheduled before UI loaded:
//Native MSI UI
var project =
    new Project("MySetup",
        new ManagedAction("SetInstallDir",
public static ActionResult SetInstallDir(Session session)
    session["INSTALLDIR"] = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\7-Zip")
    return ActionResult.Success;
var project =
    new ManagedProject("MySetup",
project.UILoaded += project_UIInit;
static void project_UIInit(SetupEventArgs e)
    e.Session["INSTALLDIR"] = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\7-Zip")
Please note that in older releases ManagedUI had a problem initializing the installdir text box. Thus please use the vary latest release where it's fixed.
Mar 9, 2016 at 9:36 AM
Thank you.
This is great to be able to change INSTALLDIR and this is partly what I want, however I actually wants the main files to go to %programfiles\MyCompany\MyApp and then if (7-Zip) is detected I want to add files into that folder.

How can I do that?
Mar 9, 2016 at 9:49 AM
Update on this.
If I change the TARGETDIR property rather than the INSTALLDIR, it will let me install the files as wanted.
Mar 9, 2016 at 10:39 AM
Then you will need to create another additional directory branch:
new Dir(@"%ProgramFiles%\My Company\My Product",
    new File(@"..\Files\bin\MyApp.exe"),
    new Dir("Docs",
        new File("readme.txt"))),
new Dir(new Id("TOOLSDIR"), "Tools", 
    new File("setup.cs")),
And now set TOOLSDIR property the same way as in my prev example.

Keep in mind that as an alternative to events you you can also play with the dedicated RegValueProperty actrion
new RegValueProperty("TOOLSDIR",
                    defaultValue: @"C:\My Company\tools")
Mar 9, 2016 at 11:55 PM
> If I change the TARGETDIR property rather than the INSTALLDIR, it will let me install the files as wanted.
This extra post has puzzled me. You stated that you want to control both installdir and customdir individually and yet you are saying that changing a single out-most root point solves the problem. I don't see how... but hey, if you are happy... :)
Mar 14, 2016 at 8:52 AM
He he, I see your point and I might have been a bit too fast there :-)
Sorry if I confused someone with that post, I have changed the code since that to something like the suggested.

That been said, I think Wix# is awesome, you are doing a great job here Oleg.