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.01k stars 1.72k forks source link

Add Support for WinUI Unpackaged Apps #3166

Closed mattleibow closed 1 year ago

mattleibow commented 2 years ago

Summary

Since the release of the Windows App SDK Preview 3, we can now use unpackaged apps: https://docs.microsoft.com/en-us/windows/apps/winui/winui3/create-your-first-winui3-app?pivots=winui3-unpackaged-csharp

.csproj changes

-<WindowsPackageType>MSIX</WindowsPackageType>
+<WindowsPackageType>None</WindowsPackageType>

Improved self contained:

+<WindowsAppSDKSelfContained Condition="'$(IsUnpackaged)' == 'true'">true</WindowsAppSDKSelfContained>
+<SelfContained Condition="'$(IsUnpackaged)' == 'true'">true</SelfContained>

launchSettings.json changes

 {
   "profiles": {
     "Windows Machine": {
-      "commandName": "MsixPackage"
+      "commandName": "Project"
     ,
   }
 }

You will need to download and install the Windows App SDK runtime and MSIX packages which are required to run and deploy unpackaged apps: https://docs.microsoft.com/en-us/windows/apps/windows-app-sdk/downloads

For example, for the stable 1.0.0 version of the Windows App SDK, you will need to download and install: https://aka.ms/windowsappsdk/1.0-stable/msix-installer

In order to install the SDK, you may need to manually install the App Installer first: https://www.microsoft.com/store/productId/9NBLGGH4NNS1

Work To Do

Some changes we need to make/have:

Related Issues

mattleibow commented 2 years ago

@Eilon could you review all the usages the Xxx.Current listed above in the blazor parts. @danroth27 got Blazor working as unpackaged, so I am not sure how it all worked. Just invoking the Current property causes a crash, so you must be working some magic!

mattleibow commented 2 years ago

a lot of code can probably come from here: https://github.com/xamarin/Essentials/pull/1079

mattleibow commented 2 years ago

@javiercn here is a list of things to check for.

javiercn commented 2 years ago

@mattleibow I tried this on the maui repo and it doesn't seem to be working:

image

The issue happens both with the sandbox and the single project projects. I did setup things up as described above

javiercn commented 2 years ago

@mattleibow I have a PR out that makes Blazor Webview support this. What's the way to publish an unpackaged Win UI Maui app?

mattleibow commented 2 years ago

Have a look at the suff in the description of this issue. 2 places. 1 line each.

Eilon commented 2 years ago

@mattleibow reopened this 5 minutes ago

Oops, sorry!

DanJBower commented 2 years ago

In terms of unpackaged apps, if it is using an exe rather than msix, does that mean that creating a self-contained exe would be supported? As in an exe I can share and people can run without installing

That would be a massive benefit to me in terms of my workplace is very restrictive which makes installing windows apps almost impossible

mattleibow commented 2 years ago

Yes, but I am not sure if WinUI is ready for that just yet. I think there is ongoing discussion on this windows self contained story.

Might be a 1.1 or 1.2 feature.

DanJBower commented 2 years ago

Yes, but I am not sure if WinUI is ready for that just yet. I think there is ongoing discussion on this windows self contained story.

Might be a 1.1 or 1.2 feature.

Ah okay. Thanks for the clarification

mattleibow commented 2 years ago

With WASDK 1.1.x I believe the self contained story is almost done but there is just a bug in the targets file now. I have updated the description for the self contained story.

Current blocking issue https://github.com/microsoft/WindowsAppSDK/issues/2684

javiercn commented 2 years ago

@mattleibow I believe we already did all we needed to do in Blazor Webview for this at the time, but if there are new requirements to make this work, please let us know. I believe, ideally we want this scenario to be available for Blazor Maui apps.

mattleibow commented 2 years ago

I created a repo and this commit converts the current public maui from a a packaged app to an unpackaged app: https://github.com/mattleibow/MauiUnpackaged/commit/12fef2e1aecc7f6808dcf4ddb6281bac51db50c9

Once some PRs are merged, all this goes away.

mprogers commented 2 years ago

I got our IT group to install Visual Studio 2022 (woo-hoo!) since it's come out of preview, brilliant timing. However, trying to run a .NET MAUI Windows App just now gave me an error - I need to enable developer mode. I have a feeling our IT staff is not going to be amenable to this, and my search led to this issue. Am I in the right place? And is there a way around this? I thought perhaps I could do Android, but that too required admin credentials.

markushaslinger commented 2 years ago

I got our IT group to install Visual Studio 2022 (woo-hoo!) since it's come out of preview, brilliant timing. However, trying to run a .NET MAUI Windows App just now gave me an error - I need to enable developer mode. I have a feeling our IT staff is not going to be amenable to this, and my search led to this issue. Am I in the right place? And is there a way around this? I thought perhaps I could do Android, but that too required admin credentials.

We are in the same situation, but as a college: would love to do MAUI dev with the students, but the IT stuff is very reluctant to enable developer mode => it's already a no-go for the current year now, but I hope this restriction will be lifted and we can give it a go next year.

MagicAndre1981 commented 2 years ago

for android you also need to enable developer options and allow USB/Wifi debugging to deploy/debug apps. So there is no difference

markushaslinger commented 2 years ago

for android you also need to enable developer options and allow USB/Wifi debugging to deploy/debug apps. So there is no difference

The difference is that phones are owned and operated by students, plus we can use the emulator. The PCs are managed by our IT staff who refuse to turn on developer mode so we are stuck with WPF for now. If possible, I'd like this requirement to be removed.

mattleibow commented 1 year ago

Closing this as I believe all the bits of code should now be working or have known issues. See #8552 for the complete list.