Passing user data to after_install

Nov 18, 2015 at 11:50 AM
Hi all,
I have managed setup with one custom dialog.(I'm asking user for some data (IP address, actually)). Using MsiRuntime.Session["IPADDRESS"] for storing user input.
I'm using Custom UI Dialog from samples as basis.
After installation a want to edit some files in INSTALLDIR, adding this user data to config files ...
project.AfterInstall += project_AfterInstall;
and in project_AfterInstall(SetupEventArgs e) i'm trying to edit config files.
When I tried to use e.session["IPADDRESS"] i get an exception "Cannot access session details from non immediate custom action"

So my question is how to pass this user input to AfterInstall func?
Or please point me to right place in documentation..

Thank you!
Nov 18, 2015 at 10:57 PM
The problem is caused by the MSI limitation, which prevents user from accessing ANY property from the deferred custom actions (e.g. project.AfterInstall) due to the Session object being already disconnected.

Fortunately there is a work around - CustomActionData. It is a "sacred" place where copies of the properties can be placed by specially crafted property packing custom action. Wix# allows doing all with a single line of code. You just have to nominate (with DefaultDeferredProperties) what property needs to be tunneled to the Project.AfterInstall event handler. This is a fragment for the CustomUIDialog sample:
//if the property 'PASSWORD' is not preserved as deferred then it will not be available 
//from the Project_AfterInstall, which is a deferred custom action.
project.DefaultDeferredProperties += ",PASSWORD"; 
static void Project_AfterInstall(SetupEventArgs e)
    if (e.IsInstalling)
        MessageBox.Show($"User '{Defaults.UserName}' with password '{e.Session.Property("PASSWORD")}' has been created");
Note that I am using e.Session.Property("PASSWORD") instead of e.Session["PASSWORD"]. This is because the session object is disconnected and contains no data. However the extension method Property() transparently accesses data either form Session or Session.CustomActionData depending which one is available.
Marked as answer by Ngobo on 11/19/2015 at 3:32 AM
Nov 18, 2015 at 11:34 PM
BTW in the very latest release v1.0.29.0 you can use new field IsDeferred:
new Property("PASSWORD", "pwd123") { IsDeferred = true })
It has the same effect as
project.DefaultDeferredProperties += ",PASSWORD"; 
Nov 19, 2015 at 10:33 AM
Thank you! It works.