dotnet / maui

.NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop.
https://dot.net/maui
MIT License
22.04k stars 1.73k forks source link

Unable to run Windows application from command line #5975

Open eerhardt opened 2 years ago

eerhardt commented 2 years ago

Description

I am unable to launch my Maui Windows application from the command line. With Android I can with dotnet build -t:Run. But this doesn't work with Windows. Note that dotnet run -f net6.0-windows10.0.19041.0 also doesn't work.

cc @mattleibow

Steps to Reproduce

  1. dotnet new maui
  2. dotnet build -t:Run -f net6.0-windows10.0.19041.0

Results

C:\git\maui\bin\dotnet\sdk\6.0.300-preview.22207.16\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(901,5): er
ror MSB3073: The command "C:\DotNetTest\MauiTest\bin\Debug\net6.0-windows10.0.19041.0\win10-x64\MauiTest.exe " exited w
ith code -532462766. [C:\DotNetTest\MauiTest\MauiTest.csproj]

Version with bug

Unknown/Other (please specify)

Last version that worked well

Unknown/Other

Affected platforms

Windows

Affected platform versions

All Windows

Did you find any workaround?

No response

Relevant log output

When attaching a Debugger to the process, I see:

System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
  Source=MauiTest
  StackTrace:
   at MauiTest.WinUI.Program.XamlCheckProcessRequirements()
   at MauiTest.WinUI.Program.Main(String[] args) in C:\DotNetTest\MauiTest\obj\Debug\net6.0-windows10.0.19041.0\win10-x64\Platforms\Windows\App.g.i.cs:line 28

Depends on

v-longmin commented 2 years ago

Verified the issue on 17.2.0 Preview 2.1 [32317.152.main], it's repro.

jsuarezruiz commented 2 years ago

Could be related with https://github.com/dotnet/maui/pull/5923? cc @mattleibow

mattleibow commented 2 years ago

Not sure... I don't know if there is a way to run WinUI apps from the CLI, either with msbuild or dotnet.

mattleibow commented 2 years ago

Opened this discussion to be able to find out the way to do things: https://github.com/microsoft/WindowsAppSDK/discussions/2391

mattleibow commented 2 years ago

Might even be related to this discussion: https://github.com/microsoft/WindowsAppSDK/issues/55

Not sure if there is a way to launch MSIX apps via the CLI, but could be via unpackaged...

mattjohnsonpint commented 2 years ago

Same here. Been doing everything on a Mac so far, where dotnet build -t:Run -f net6.0-maccatalyst (or -ios, -android, etc.) works fine. Thought I'd try it out on Windows and ran into this issue. It only works if I do a full VS2022 preview install and run from within VS. Seems like it should work on the command line for consistent experience.

geronimus commented 2 years ago

Now that the .NET MAUI general availability release has happened, is there any timeline on resolving this issue?

Some Microsoft material released last year indicated that it was perfectly feasible to develop .NET MAUI apps using only VS Code. (Which means you must be able to do it using only vi too... which is my goal... crazy though that may seem!)

To me, this means that there may be a work-around for this issue that the Microsoft insiders have access to. Perhaps it could be posted here as a viable alternative. That is, until the non-VS experience on Windows works out-of-the-box.

ghost commented 2 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

mattleibow commented 2 years ago

I also see that doing a dotnet build -t:Run -f net6.0-windows10.0.19041.0 on a fresh project does not restore or build. I had to add a separate dotnet build as well in order for it to do something.

However, I was able to get something to run with unpackaged:

dotnet build /restore -f net6.0-windows10.0.19041.0  /p:WindowsPackageType=None
dotnet build -t:Run -f net6.0-windows10.0.19041.0  /p:WindowsPackageType=None

But we still also need to get dotnet run working with anything:

The launch profile "(Default)" could not be applied.
A usable launch profile could not be located.
mattleibow commented 2 years ago

Moving the issue here as well: https://github.com/microsoft/WindowsAppSDK/issues/2922

DrusTheAxe commented 2 years ago

Not sure if there is a way to launch MSIX apps via the CLI, but could be via unpackaged...

Sure! There's a few

Activation via AUMID:

shell:appsfolder\...aumid... e.g. ShellExecute("shell:appsfolder\Microsoft.WindowsCalculator_8wekyb3d8bbwe!App") launches Calculator. Try it from the Win-R prompt.

Activation via Executable:

On Win11 if you run a packaged app's exe from its package directory Windows figures out it's a packaged app and runs it e.g. CreateProcess(GetPackagePath(p) + "\foo.exe") is equivalent to ActivateApplication(fooApplicationUserModelId). This is sometimes referred to as PackagedCreateProcess.

NOTE: This requires the executable be declared for only 1 app in the package e.g. you can declare multiple <Application> in appxmanifest.xml (technically, 0-100) but <Application Executable="foo.exe"...> must be unique. If 2 <Application>s declare the same Executable Windows can't launch the app by running its exe. As you might guess, when running the packaged exe Windows does a xref against apps in the package using the exe so 2+ would be ambiguous.

Alternatively on 20H1+, if the executable has a Fusion manifest declaring <msix...> then you can CreateProcess() the app's exe. CreateProcess sees the manifested identity, does a lookup against packages registered to the user to find the application's details and voila! This is equivalent to PackagedCreateProcess, though it requires <msix> (on the upside, it predates PackagedCreateProcess so available further downlevel). See https://docs.microsoft.com/en-us/windows/win32/sbscs/application-manifests#msix. NOTE: The docs talk about sparse MSIX packages; that's a scenario where this is useful, but <msix> is a mechanism, it doesn't care about WHY you use it - you can use <msix> whether or not you have a sparse package.

NOTE: Running an executable by typing it into a command line invokes CreateProcess (or ShellExecute, depending on the command prompt). These are options you can use to interactively launch MSIX packaged apps. Programmatically there's additional options.

AvtsVivek commented 1 year ago

I think the issue I raised here on SO is similar.

homeyf commented 1 year ago

Verified this issue with Visual Studio 17.6.0 Preview 2.0. Repro on Windows application from command line.

tilkinsc commented 8 months ago

Still an issue in 2024 btw

samhouts commented 6 months ago

This is still blocked on https://github.com/microsoft/microsoft-ui-xaml/issues/7331 and other related issues. Thank you for your patience!

ardalis commented 1 month ago

Still an issue today.

tilkinsc commented 1 month ago

How do you actually build/run a maui app on windows then? I only use VSCode.

sdheer commented 19 hours ago

i use the following for running the windows application. build dotnet build -f net8.0-windows10.0.19041.0 -c Debug -p:PublishReadyToRun=true -p:WindowsPackageType=None and for run dotnet run -f net8.0-windows10.0.19041.0 -c Debug -p:PublishReadyToRun=true -p:WindowsPackageType=None