Reputation: 977
I am using wix sharp to develop my installer and everything is working fine except I'm unable to provide the install directory location at run time. While installation, I'm taking input from user and storing them in environment variable as "InstallFolder" and in wix sharp code I'm taking this from Environment variable.
var installLocation = Environment.GetEnvironmentVariable("installLocation",
EnvironmentVariableTarget.User);
var XYZ_project = new ManagedProject("xyz_Product",
new Dir(installLocation,new Files(@"xxx\yyy\*.*"))
Ideally it should take the instalLocation from env variable but it is not taking it at runtime. If I set this value before building the installer itself it is taking the value.
I need to get the values from user on runtime and set them. Please suggest on this.
Upvotes: 0
Views: 1005
Reputation: 4676
To set install dir at runtime, you can use ManagedProject.Load
event.
In the project declaration set the root directory ID ("DIR1" in the sample) and subscribe to the Load
event.
var project =
new ManagedProject("MyProduct",
new Dir(new Id("DIR1"), "root1", new File("test.exe")));
project.Load += Project_Load;
In event handler set the value for the dir
static void Project_Load(SetupEventArgs e)
{
e.Session["DIR1"] =
Environment.GetEnvironmentVariable("installLocation",
EnvironmentVariableTarget.User);
}
The Project_Load
will be called on client machine before the installation, but after all user input collected.
See full sample here and documentation about wix# event here.
Upvotes: 2
Reputation: 708
I see that you're grabbing the environment variable in the User context. Have you tried it with the context set to Machine or Process? The installExecuteSequence that does the actual install runs in the context of System. I'm guessing this might fix this for you.
Upvotes: 0