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

Add custom Wizard-like Installer to Bundle / Burn Installer #1554

Closed Torchok19081986 closed 5 months ago

Torchok19081986 commented 5 months ago

morning, i created custom UI for Installer Wizard-like as Demo. Now i struggle to add it to Bundle. I tried to add it , but burn ignores my installer. I need some help to get it in right direction. Is there some guidline how to implement custom UI to bundle for v4 or better for v5 ? Standard WPF Template cant be modified for my purpose, unfortunatelly.

i want to create UI with custom Dialogs like FeatureTree etc. Purpose for this is create UI that i can use for Installers same UI for multiple project . I found out, how to show all files that will be "copy" / installed on target system.

oleg-shilo commented 5 months ago

If you are talking about MSI UI that it displayed from the bootstrapper exe then you need to set DisplayInternalUI = true.

var bundle = new Bundle("My Product Bundle",
                 new MsiPackage(productMsi)
                 {
                     Id = "MyProductPackageId",
                     DisplayInternalUI = true
                 });
Torchok19081986 commented 5 months ago

hiho Oleg, unfortunatelly not. I have to use custom Bootstrapper UI for MSI , case from bundle UI to msi package where in UI only reflected installer progress , similar to one of your example UI for Bundle. I just , at moment, cant figure out, how to tell bundle use my custom ui. MSI has publc property , that can only be started from exe. BUT all my efforts to add my custom UI , are failed, misserably. Bundle doesnt want use it. In MSI i can add assembly to use theme or UI, but not in bundle.

oleg-shilo commented 5 months ago

I think I might be missing something.

Are you trying to create a boostrapper with the stock UI that is installing an MSI that has custom (non-stock) UI? or Are you trying to create a boostrapper with the custom (non-stock) UI that is installing an MSI that has custom/stock UI?

Torchok19081986 commented 5 months ago

sorry, i dont write clearly. my mistake.

I think I might be missing something.

Are you trying to create a boostrapper with the stock UI that is installing an MSI that has custom (non-stock) UI? or Are you trying to create a boostrapper with the custom (non-stock) UI that is installing an MSI that has custom/stock UI?

I try second part. I am trying to create a boostrapper with the custom (non-stock) UI that is installing an MSI that has custom/stock UI.

i try to add my project. Pls, look at it, if you had some time.

InstallWizardDemo.zip

oleg-shilo commented 5 months ago

Unfortunatelly, you have no good way achieving this.

WiX4 does not provide simple unified way of controllong MSI internal UI. Thus DisplayInternalUI does not work from custom BA and you need to use another WiX4 mechanism - PlanMsiPackage.

public ManagedBA(mba.IEngine engine, mba.IBootstrapperCommand command) : base(engine)
    {
        this.Command = command;
        this.PlanMsiPackage += (s, e) =>
        {
            if (e.PackageId == "MyProductPackageId")
            {
                e.UiLevel = (e.Action == ActionState.Uninstall) ?
                               INSTALLUILEVEL.ProgressOnly :
                               INSTALLUILEVEL.Full;
            }
        };
    }

The guidance is captured here. I have attached the sample too.


Though in case of "MSI custom UI", to my disbelieve, the BA is shows the msi UI but the stock one instead of the custom one. Even though executing msi alone shows the correct custom UI. Meaning that the technique that I learned from WiX team with such difficulties works only partially (for msi stock UI only).

I tested your scenario before the first release of WixSharp wix4 stream and I was under impression that it worked. But I have to accept that it is can only be explained by the recent changes in wix4 or by me mistakenly interpreting msi stock UI as custom one, meaning that wix4 never worked in the first place. TBH my misinterpretation is quite possible as wix3 just did not show the UI at all so when UI popped I could just take it as WixSharp own UI (msi custom UI).

I suggest you test this work around (PlanMsiPackage) as there is a small chance that what I am observing right now is caused by my environment. I hope so.

If indeed it is a problem with WiX or the way we are using it, the chances of fixing it are very low. It's very unlikely asking WiX team for explanations will help. At least if I ask :)

As a plan be you can have a look at the work around that achieves the desired result reliably but it is rather unorthodox. image

Bootstrapper Custom BA (WiX4).zip

oleg-shilo commented 5 months ago

Now NSIS looks more and more attractive :)

Torchok19081986 commented 5 months ago

morning, thanks again @oleg-shilo for explanation. I did not much with NSIS Bootstrapper and WixToolset / WixSharp. for wix5 : Is there possiblity wix5 hosting ba out of process, can in future, cover such scneario or it is something another way ? I thought , i can chage one of your example to do this way. Example that i refer is ExternalUI/WpfSetup. This were my startpoint. This is exactly scenario i would like to use, BUT here i need to change UI and add wizard-like UI. MSI "embded" in UI and reflects only progress on UI. I seem many ba installer with custom UI where only 3 or 4 dialogs. Welcome, Installdir, Progress und Exit Dialogs thats it. Not all of them use MS Installshield Wizard and ~50% use wixtoolset, because log show wix toolset. I will try your suggestion with workaround and see what outcome is.

oleg-shilo commented 5 months ago

Is there possiblity wix5 hosting ba out of process

I don't know. It's really a question to the WiX team about the product roadmap.

MS Installshield Wizard

Not sure I follow. Maybe it is a typo here.

I will try your suggestion with workaround and see what outcome is.

Absolutely. You do not risk anything by suggesting it.

. . .

After some further consideration I have decided to implement WixSharp own msi pseudo-package that would overcome WiX limitation. It will be based on the ExePackage sample that I shared with you. It will help devs to face the same challenges as you do.

The intended syntax will be somewhat similar to this:

var bootstrapper = new Bundle("My Product",   
                       new MsiExePackage("product.msi")
                       { 
                           DisplayInternalUI = true
                       });
. . .

This would yield the same wxs/msi as currently this code would do:

var msi_upgrade_code = new MsiParser.GetProductCode("product.msi");
var bootstrapper = new Bundle("My Product",
                       new ExePackage("product.msi.exe") // WixSharp own msi launcher with product.msi embedded as a resource
                       {
                           Name = new MsiParser.GetProductName("product.msi"),
                           InstallArguments = "/i",
                           UninstallArguments = "/x",
                           RepairArguments = "/fa",
                           DetectCondition = "ProductInstalled",
                           Compressed = true
                       });

. . .

bootstrapper.AddWixFragment("Wix/Bundle",
    new UtilRegistrySearch
    {
        Root = RegistryHive.LocalMachine,
        Key = $@"SOFTWARE\Microsoft\Windows\CurrentVersion\Installer\UserData\S-1-5-18\Products\{msi_upgrade_code}",
        Value = "DisplayName",
        Result = SearchResult.exists,
        Variable = "ProductInstalled"
    });
Torchok19081986 commented 5 months ago

morning, i just tried your code. Many thanks for sharing it. Somehow it produced nullref exeception with code

System.NullReferenceException: Der Objektverweis wurde nicht auf eine Objektinstanz festgelegt.
1>       bei WixSharp.Bootstrapper.Bundle.ToXml()
1>       bei WixSharp.Compiler.BuildWxs(Bundle project)
1>       bei WixSharp.Compiler.Build(Bundle project, String path)
1>       bei WixSharp.Compiler.Build(Bundle project)
1>       bei WixSharp.Bootstrapper.Bundle.Build(String path)
1>       bei Bootstrapper_Custom_BA__WiX4_.Program.Main()

Msi is building compelte and also msi file exists, but bundle not. Added wixextension for util and bal , doesnt do anything better.

oleg-shilo commented 5 months ago

This is what is working: 340057642-f532045d-8665-4bb2-8fc1-daad03a79826

I am not sure what exactly you are testing so cannot comment. But keep in mind that new ExePackage("product.msi.exe") is a pseudo-code. I do not have yet the solution for building such msi-hosted exe. In the sample I mention I built the exe by hands.

Torchok19081986 commented 5 months ago

hm, ok, thanks again. Just tried, your example in samples works. ok, i will look at it some time later.

oleg-shilo commented 5 months ago

Done. Will be available in the very next release.

oleg-shilo commented 5 months ago

Your scenario sample: https://github.com/oleg-shilo/wixsharp/blob/9c9b0444c60f129f28c9c66dfd1a0ae8470b1443/Source/src/

    static public void Build(string msi)
    {
        // This sample does what ManualBuild does but in a single step. This is because there is no need to build
        // self-hosted msi as it is automatically built in MsiExePackage constructor.

        Console.WriteLine("Building Bootstrapper ...");

        var bootstrapper =
            new Bundle("Managed Product Bundle",
                       new MsiExePackage(msi)
                       {
                           Name = "ManagedProduct",
                       });

        bootstrapper.Version = new Version("1.0.0.0");
        bootstrapper.UpgradeCode = new Guid("6f330b47-2577-43ad-9095-1861bb25889a");

        bootstrapper.Build("my_app.exe");
    }

WixSharp.Samples/Wix%23%20Samples/Bootstrapper/WixBootstrapper_EmbeddedUI/setup.cs#L27