post-install action in ManagedProject

Jun 30, 2016 at 9:58 AM
Hi!
I created new managed setup custom UI project. Then I added project.AfterInstall event. I run my MSI installer. In ExitDialog I saw that My Product setup was interrupted.
When I deleted project.AfterInstall event setup was completed successfully.
How can I complete the setup and use project.AfterInstall event?
Coordinator
Jul 1, 2016 at 12:50 AM
Most likely there was something in your AfterInstall handler that trows the exception and interrupts the setup. If it is the case the error will be present in the log file. The log file can be conveniently accessed from the ExitDialog via "ViewLog" link:

Image

I also (just in case) tested the current NuGet package with your scenario and it does complete the install successfully with the AfterInstall handler. You cane test it by yourself. The project is here: https://dl.dropboxusercontent.com/u/2192462/natka/WixSharp%20Setup3.7z.
Jul 5, 2016 at 9:16 AM
Edited Jul 5, 2016 at 10:28 AM
Thanks for reply. You was right, an exception interrupted the setup.

Now I want to transfer data from custom dialog to AfterInstall handler. I tried to do this through Data and Session:

public partial class WebSettingsDialog : ManagedForm, IManagedDialog
{
....
void next_Click(object sender, EventArgs e)
{
    MsiRuntime.Session["PORT"] = port.Text;
    MsiRuntime.Data["DATABASE_CONNECTION_STRING"] = connectionDBString.Text;
    Shell.GoNext();
}
}

In AfterInstall handler I received empty strings:
    static void project_AfterInstall(SetupEventArgs e)
    {
        try
        {
            if (e.IsInstalling)
            {   
        string connectionString = e.Data["DATABASE_CONNECTION_STRING"];
        MessageBox.Show("DATABASE_CONNECTION_STRING: " + connectionString);
        MessageBox.Show("PORT: " + e.Session.Property("PORT"));
    }
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error: " + ex.Message);
        }
    }
e.Session.Property("PORT") in BefoteInstall handler gave me right string.
e.Data["DATABASE_CONNECTION_STRING"] in BefoteInstall handler gave me empty string
  1. Why Visual Studio doesn't stop at the breakpoints in BefoteInstall and AfterInstall handlers?
    I have to debug by messageboxes in this handlers.
Coordinator
Jul 6, 2016 at 5:36 AM
Thank you, it is a defect. I have created the issue on your behalf: https://wixsharp.codeplex.com/workitem/128
The MsiRuntime.Data got overwritten by accident before being passed into your event handler.

A hot fix is available via prerelease on NuGet: "Release 1.0.40.1-HotFix"

> Why Visual Studio doesn't stop at the breakpoints in BefoteInstall and AfterInstall handlers? I have to debug by messageboxes in this handlers.
There are quite a few reasons for difficulties with debugging.

The most common one is that your VS has to be elevated. You probably already know that.

Another one that you have to attach VS to the running process but not select the VS instance from the assertion box. Very often VS doesn't play nice the other way around.

The most annoying one is that MSI executes every custom action in a dedicated process. One per CA. Thus after you attached and debugged one custom action you need to detach and attach your debugger to the next CA process with the assertion (or messagebox). The process is rundll32.exe

Yes this is how ugly MSI runtime model is :)
Jul 6, 2016 at 7:15 AM
Hi, Oleg!
Thank you, now I can debug AfterInstall handler by attaching to rundll32.exe.

I set MsiRuntime.Data["DATABASE_CONNECTION_STRING"] in custom dialog.
And e.Data["DATABASE_CONNECTION_STRING"] in AfterInstall handler returns null.
Coordinator
Jul 6, 2016 at 7:17 AM
But did you get the prerelease from NuGet?

Oleg Shilo
--------------------------------------------------------------------------------------------
Website: http://www.csscript.net
E-Mail: [email removed]

Coordinator
Jul 6, 2016 at 10:28 AM
I just checked on NuGet server the release with the fix (v1.0.40.1-HotFix) hasn't been downloaded yet.

This is what you need:
Install-Package WixSharp.bin -Pre
Jul 7, 2016 at 6:39 AM
I use v1.0.40.1-HotFix. e.Data["DATABASE_CONNECTION_STRING"] in AfterInstall handler returns null.
When I use v1.0.40.0 e.Data["DATABASE_CONNECTION_STRING"] in AfterInstall handler returns empty string.
Coordinator
Jul 7, 2016 at 11:49 AM
Edited Jul 7, 2016 at 1:22 PM
Thank you. The fix only covered ManagedSetup events. I just missed ManagedUI case. I extended the fix and now your scenario is also covered. The Nuet package version is v1.0.40.2-HotFix. I also just in case prepared a complete test project: https://dl.dropboxusercontent.com/u/2192462/Wix%23-Binaries/WixSharp%20Setup3.7z

Please let me know if the issue is addressed now.
Jul 12, 2016 at 10:57 AM
Edited Jul 12, 2016 at 10:58 AM
Hi, Oleg!
Now I use v1.0.40.2-HotFix.
In custom dialog I set:
MsiRuntime.Data["DATABASE_CONNECTION_STRING"] = @"Data Source=.\SQLEXPRESS;Initial Catalog=RequestManagement;Integrated Security=SSPI".
e.Data["DATABASE_CONNECTION_STRING"] in AfterInstall handler returns "Data Source".
Coordinator
Jul 12, 2016 at 12:48 PM
Edited Jul 12, 2016 at 12:56 PM
OK I see.
MsiRuntime.Data at runtime is serialized into semicolon delimited key-value pares and because MSSQL is using the same encoding technique for connection strings it interferes with the Wix# MsiRuntime.Data serialization.

It is a Wix# problem and it will need to take about escaping ; and = in user input values. Currently it does it for line breaks only. As a very temporary work around you can use your own escaping. Something like this:
var conn = @"Data Source=.\SQLEXPRESS;Initial Catalog=RequestManagement;Integrated Security=SSPI";
MsiRuntime.Data["DATABASE_CONNECTION_STRING"] = conn.Replace(";", "&#59;")Replace("=", "=");
...
var conn = MsiRuntime.Data["DATABASE_CONNECTION_STRING"];
conn =  = conn.Replace("&#59;", ";").Replace("=", "=");
Thank you. I'll keep you informed on the fix availability. It will happen very soon. Most likely today.

P.S. I also created the issue on your behalf: https://wixsharp.codeplex.com/workitem/130
Coordinator
Jul 12, 2016 at 9:55 PM
Can you please test the latest NuGet release v1.0.40.3
Install-Package WixSharp.bin -Pre
It should do the escaping/unescaping automatically
Coordinator
Jul 14, 2016 at 6:04 AM
Fixed in Release v1.0.41.0