Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinUI3 apps close after showing the splash screen when launched with an executionAlias #3441

Closed
mrlacey opened this issue Oct 18, 2020 · 15 comments
Labels
product-winui3 WinUI 3 issues version-winui3preview4 WinUI 3 Preview 4 issues

Comments

@mrlacey
Copy link
Contributor

mrlacey commented Oct 18, 2020

Describe the bug

If a WinUI3 app is launched with an execution alias the app starts but automatically closes after briefly showing the splash screen.

Steps to reproduce the bug

Steps to reproduce the behavior:

  1. Create a new, empty WinUI3 desktop app from the VSIX template (version 3.0.0.2007130)
  2. Add the following to package.appxmanifest as a child of the App element.
        <Extensions>
            <uap5:Extension
                Category="windows.appExecutionAlias"
                Executable="$targetnametoken$.exe"
                EntryPoint="$targetentrypoint$">
                <uap5:AppExecutionAlias>
                    <uap5:ExecutionAlias Alias="MyTestApp.exe" />
                </uap5:AppExecutionAlias>
            </uap5:Extension>
        </Extensions>

(If using a UWP app set the EntryPoint as {AppName}.App)

  1. Add the XML Namespace alias xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
  2. Run the app from VS to deploy it locally
  3. Run the app from the command line c:\> MyTestApp.exe

Expected behavior

App should launch without issue

Screenshots

Version Info

NuGet package version:
Microsoft.WinUI 3.0.0-preview2.200713.0

Windows app type:

UWP Win32
Yes Yes
Windows 10 version Saw the problem?
Insider Build (xxxxx)
May 2020 Update (19041) Yes
November 2019 Update (18363)
May 2019 Update (18362)
October 2018 Update (17763)
April 2018 Update (17134)
Fall Creators Update (16299)
Creators Update (15063)
Device form factor Saw the problem?
Desktop Yes
Xbox
Surface Hub
IoT

Additional context

If in a WinUI3 UWP app, setting the Start action as "Do not launch, but debug my code when it starts" and adding a break point in the App Constructor , the break point is never hit. (I don't know how to test the equivalent in a desktop app--or if it's possible)

The error code/level after unsuccessfully launching an app from an alias is reported as 0. This is a success error code and so is misleading.

The same/equivalent functionality works fine for a pre-WinUI3/regular UWP app.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Oct 18, 2020
@ranjeshj ranjeshj added product-winui3 WinUI 3 issues and removed needs-triage Issue needs to be triaged by the area owners labels Oct 19, 2020
@mrlacey
Copy link
Contributor Author

mrlacey commented Nov 23, 2020

For the desktop app, I've also tried overriding the OnActivated event in the main app, and also defining DISABLE_XAML_GENERATED_MAIN and creating my own main method but this doesn't work with the executionAlias either. :(

@mrlacey
Copy link
Contributor Author

mrlacey commented Nov 23, 2020

Without this functionality it is not possible to pass command-line arguments to apps.
While "Desktop" apps are being equated with "Win32" apps I feel the lack of command-line support is a big gap.

Currently this issue isn't even mentioned on the roadmap. With the GA release planned for H12021 and quarterly point releases after that, it looks as if command line support won't be available until at least Q4 2021.

This is a serious blocker for allowing WinUI3 apps from integrating with existing apps.

@marb2000
Copy link
Contributor

I can still repro this in Preview 4.

@marb2000
Copy link
Contributor

marb2000 commented Feb 17, 2021

@mrlacey I made it work using the uap3:

<Package
  ...
  xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
  xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"
...
IgnorableNamespaces="uap rescap uap3">


    <Extensions>
        <uap3:Extension
              Category="windows.appExecutionAlias"
              EntryPoint="Windows.FullTrustApplication">
          <uap3:AppExecutionAlias>
            <desktop:ExecutionAlias Alias="MyTest.exe" />
          </uap3:AppExecutionAlias>
        </uap3:Extension>
      </Extensions>

This is the link to the doc

Let me know if this works on your side.

@mrlacey
Copy link
Contributor Author

mrlacey commented Feb 17, 2021

@marb2000 I can confirm that I can now get this working for both UWP and Desktop apps with Preview 4. (My repro above is incomplete 😢 and I can't find my original exploratory projects so I don't know if it was me or if it has been fixed.)

Both work with uap3&desktop and uap5 aliases.

Here's how I got it working in a WinUI3 UWP app.

  • In Package.appxmanifest
    • Add the alias xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
    • Add this below </uap:VisualElements>
    <Extensions>
        <uap5:Extension
                Category="windows.appExecutionAlias"
                Executable="App231.exe"
                EntryPoint="App231.App">
            <uap5:AppExecutionAlias>
                <uap5:ExecutionAlias Alias="MyTest.exe" />
            </uap5:AppExecutionAlias>
        </uap5:Extension>
    </Extensions>

OR use

  xmlns:uap3="http://schemas.microsoft.com/appx/manifest/uap/windows10/3"
  xmlns:desktop="http://schemas.microsoft.com/appx/manifest/desktop/windows10"

   ...

    <Extensions>
        <uap3:Extension
                Category="windows.appExecutionAlias"
                Executable="App231.exe"
                EntryPoint="App231.App">
            <uap3:AppExecutionAlias>
                <desktop:ExecutionAlias Alias="MyTest.exe" />
            </uap3:AppExecutionAlias>
        </uap3:Extension>
    </Extensions>

(where "App231" is the name of the app/project and "MyTest.exe" is the alias to use to launch the app.)
Either set of extension (aliases) work the same.

  • In App.xaml.cs add
    protected override void OnActivated(IActivatedEventArgs args)
    {
        base.OnActivated(args);

        Frame rootFrame = Window.Current.Content as Frame;

        if (rootFrame == null)
        {
            rootFrame = new Frame();
            rootFrame.NavigationFailed += OnNavigationFailed;
            Window.Current.Content = rootFrame;
        }

        rootFrame.Navigate(typeof(MainPage));
        Window.Current.Activate();
    }

Here's how I got it working in a WinUI Desktop app:

  • In App.xaml.cs of the main project, add:
    protected override void OnActivated(IActivatedEventArgs args)
    {
        base.OnActivated(args);

        if (args.Kind == ActivationKind.CommandLineLaunch)
        {
            m_window = new MainWindow();
            m_window.Activate();
        }
    }
  • In Package.appxmanifest (of the "Package" project)
    • Add the alias xmlns:uap5="http://schemas.microsoft.com/appx/manifest/uap/windows10/5"
    • Add this below </uap:VisualElements>
    <Extensions>
        <uap5:Extension
                Category="windows.appExecutionAlias"
                EntryPoint="Windows.FullTrustApplication">
            <uap5:AppExecutionAlias>
                <uap5:ExecutionAlias Alias="MyDesktopTest.exe" />
            </uap5:AppExecutionAlias>
        </uap5:Extension>
    </Extensions>

(where "MyDesktopTest.exe" is the alias to use to launch the app.)
This also works with uap3 and desktop as above.

Important points of note:

  • Using the method with EntryPoint="Windows.FullTrustApplication" requires the restricted runFullTrust capability which cannot be used with apps distributed through the store. If using/distributing the app separately this might not be an issue. The packaging project includes the runFullTrust capability by default in the (current) project templates.
  • I tested with WinUI3-Preview4, using VS16.9.0 Preview 4.0, on Windows Insider Preview 21296.1010

@mrlacey mrlacey closed this as completed Feb 17, 2021
@BorzillaR
Copy link

Hello!
My attempts to get these solutions to work in Project Reunion desktop app have failed.

Windows 20H2 (OS Build 19042.867)
Microsoft.ProjectReunion (0.5.0-prerelease)

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 22, 2021
@StephenLPeters
Copy link
Contributor

@mrlacey does your solution work with ProjectReunion?

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Mar 23, 2021
@StephenLPeters StephenLPeters added needs-triage Issue needs to be triaged by the area owners and removed needs-triage Issue needs to be triaged by the area owners labels Mar 23, 2021
@mrlacey
Copy link
Contributor Author

mrlacey commented Mar 23, 2021

@StephenLPeters I've just run through my steps above and I can confirm that they work for me with the ProjectReunion0.5-preview packages and templates.

It would be nice if WinUI had an automated test to verify this functionality, rather than rely on manual testing for regressions ;)

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 23, 2021
@StephenLPeters
Copy link
Contributor

It would be nice if WinUI had an automated test to verify this functionality, rather than rely on manual testing for regressions ;)

Yes, totally agree! @kmahone and @Austin-Lamb . Thanks for confirming that :)

@BorzillaR do you want to take a closer look or provide more info about your scenario?

@ghost ghost removed the needs-triage Issue needs to be triaged by the area owners label Mar 23, 2021
@BorzillaR
Copy link

@StephenLPeters, I ran my app in the power shell. Now I launch it though the command prompt and it successfully showed. Should I use a different syntax to run my app through the power shell?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 25, 2021
@mrlacey
Copy link
Contributor Author

mrlacey commented Mar 25, 2021

@BorzillaR you have to have run the app at elast once before being able to launch from the alias. Is that the issue you were having?

@BorzillaR
Copy link

@mrlacey, no, I am talking about another issue.

After the first run I do the following steps

Open a command line.
Type MyDesktopTest.exe in the console.
The app starts successfully.

Then open a Power Shell window.
Type MyDesktopTest.exe there.
The app does not start at all.

Thats the issue.

@mrlacey
Copy link
Contributor Author

mrlacey commented Mar 25, 2021

@BorzillaR this looks to be a PowerShell specific issue and not at all related to the issue originally reported here.

Just typing MyDesktopTest.exe would never be expected to work. PowerShell will not launch an executable when you pass it an executable name the way it does in other consoles/terminals.

In theory using the call operator (&) should work e.g. & MyDesktopTest.exe but this doesn't work and may be worth logging as a PowerShell issue.

However, using Process-Start does work to launch an application from an alias e.g. Process-Start MyDesktopTest.exe.

Hopefully this unblocks you.

@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label Mar 25, 2021
@BorzillaR
Copy link

@mrlacey, I agree with you. This issue is not related to the original subject. The reason, I decided that it does not work, was I use the Power Shell console in my daily work. I could not imagine that the command line console would work better than Power Shell ))))

Anyway, it is strange that I can execute winver.exe from the Power Shell (whether by its name or by Start-Process) but I cannot execute MyDesktopTest.exe the same way. Another strange thing, when I type the command, which does not exist, I see a specific error in the response, but when I type MyDesktopTest.exe, there is no response. Looks like the app is launched but silently crashes.

screen1

In the command line, all work as expected.

screen2

And thank you @mrlacey for the precise and clear instructions. It was very helpful for me.

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label Mar 26, 2021
@StephenLPeters StephenLPeters removed the needs-triage Issue needs to be triaged by the area owners label Mar 30, 2021
@LaPeste
Copy link

LaPeste commented May 31, 2021

@BorzillaR you have to have run the app at elast once before being able to launch from the alias. Is that the issue you were having?

Could you elaborate a bit more on this?

@ghost ghost added the needs-triage Issue needs to be triaged by the area owners label May 31, 2021
@ranjeshj ranjeshj removed the needs-triage Issue needs to be triaged by the area owners label Jun 2, 2021
@krschau krschau removed the appModel-win32 Exclusive to WinUI 3 Win32 Desktop apps label Jul 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
product-winui3 WinUI 3 issues version-winui3preview4 WinUI 3 Preview 4 issues
Projects
None yet
Development

No branches or pull requests

7 participants