oleg-shilo / wixsharp

Framework for building a complete MSI or WiX source code by using script files written with C# syntax.
MIT License
1.12k stars 175 forks source link

The "View Log" button is broken since WixSharp-wix4.WPF version 2.2.0 for Custom WPF UI (WiX4) #1629

Open kipamgs opened 2 months ago

kipamgs commented 2 months ago

Since version 2.2.0 there is an exception thrown in the ViewLog method of the ExitDialog and thus the log is not displayed. It is working until version 2.1.7.

This happens when creating a project with WixSharp Setyp - Custom WPF UI (WiX4) and then update the nuget version.

WixToolset.Dtf.WindowsInstaller.InvalidHandleException: 'The handle is invalid.'
This exception was originally thrown at this call stack:
    [External Code]
    WixSharp_Setup2.ExitDialogModel.ViewLog() in ExitDialog.xaml.cs
        public void ViewLog()
        {
            if (shell != null)
                try
                {
                    string logFile = session.LogFile; //This line throws the exception

                    if (logFile.IsEmpty())
                    {
                        string wixSharpDir = Path.GetTempPath().PathCombine("WixSharp");

                        if (!Directory.Exists(wixSharpDir))
                            Directory.CreateDirectory(wixSharpDir);

                        logFile = wixSharpDir.PathCombine(Host.Runtime.ProductName + ".log");
                        IO.File.WriteAllText(logFile, shell.Log);
                    }
                    Process.Start("notepad.exe", logFile);
                }
                catch
                {
                    // Catch all, we don't want the installer to crash in an
                    // attempt to view the log.
                }
        }
Torchok19081986 commented 2 months ago

Hallo, i just create project from template and tested it. It works, but some code looks different.


public void ViewLog()
{
    if (Shell != null)
        try
        {
            string logFile = Host?.Runtime.Session.LogFile;

            if (logFile.IsEmpty())
            {
                string wixSharpDir = Path.GetTempPath().PathCombine("WixSharp");

                if (!Directory.Exists(wixSharpDir))
                    Directory.CreateDirectory(wixSharpDir);

                logFile = wixSharpDir.PathCombine(Host.Runtime.ProductName + ".log");
                IO.File.WriteAllText(logFile, Shell.Log);
            }
            Process.Start("notepad.exe", logFile);
        }
        catch
        {
            // Catch all, we don't want the installer to crash in an
            // attempt to view the log.
        }
}

code is from fresh generated template without any changes.

kipamgs commented 2 months ago

Your suggested change does not work for me(Host?.Runtime.Session instead of the class member session). I also reinstalled the wixsharp project templates extension in Visual Studio 2022.

Torchok19081986 commented 2 months ago

very strange. There should be logfile in temp path and folder WixSharp. If its not , msi doesnt have access to temp path or logfile. check windows eventlog for current datetime and maybe this can give you answer. Does UAC appears or msi runas for another user?

kipamgs commented 2 months ago

Yes the UAC appears. It works if you just create the project from the template and execute the installer. But as soon as you update the Nuget package to 2.2.0 or newer (at the time of writing 2.3.2 is the newest) it stops working.

With 2.1.7 the Directory (and log file) are created in C:\Users\<username>\AppData\Local\Temp. The directory is not created with a newer version (tested with 2.3.2).

Torchok19081986 commented 2 months ago

Bahmm.. Now , only oleg can help you with this. I dont update my project to newest version. But in my msi installer from template, directory and log file are created in windows temp folder, not in user specific. Last sugggestion from me, change Path.GetTempPath() to windows Temp Folder. If still doesnt created dir and file, i cant help you with. unfortunatelly.

oleg-shilo commented 2 months ago

Yes, I can confirm now it was a defect. Fixed in the today release.