maui icon indicating copy to clipboard operation
maui copied to clipboard

Add Support for WinUI Unpackaged Apps

Open mattleibow opened this issue 4 years ago • 17 comments

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

  • Packaged apps: Packaged apps are packaged using MSIX. MSIX is a package format that gives end-users an easy way to install, uninstall, and update their Windows apps using a modern UI.

    • Framework Dependent: dotnet publish -f net6.0-windows
    • Self-Contained: dotnet publish -f net6.0-windows -p:SelfContained=true -p:WindowsAppSDKSelfContained=true
  • Unpackaged apps: Unpackaged apps don't use MSIX. They're typically installed and updated using .exe or .msi files. Many unpackaged apps walk end-users through an installation wizard using a classic UI.

    • Framework Dependent: dotnet publish -f net6.0-windows -p:WindowsPackageType=None
    • Self-Contained: dotnet publish -f net6.0-windows -p:WindowsPackageType=None -p:SelfContained=true -p:WindowsAppSDKSelfContained=true
  • Self-Contained: For either Packaged or Unpackaged apps, publishing self-contained provides a way to ship a complete set of application artifacts which do not rely on any shared/globally installed frameworks.

.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:

  • [x] Allow the .net sdk to manage the native bootstrap.dll dependency (WASDK)
    This is basically putting the native dlls in the correct runtimes/win-/native/.dll path
    https://github.com/microsoft/WindowsAppSDK/pull/1498
  • [x] Upate the templates to use the win10-* RIDs: (MAUI)
    - https://github.com/dotnet/maui/pull/3185
  • [ ] Fix some cases where we assume a packaged app: (MAUI)
    Some info can be obtained from the results of this task too: https://github.com/dotnet/maui/pull/2704
    As more are found, please add it to this description so we can let the WinUI team know.
    • [ ] #8419
    • [x] Package.Current #8536
      • [x] Package.Current.InstalledLocation - I can use AppContext.BaseDirectory instead
      • [x] Package.Current.Id.Name - this could be the assembly name
      • [x] Package.Current.DisplayName - this could also be the assembly name or also look into attributes in the dll (which we could add too)
      • [x] Package.Current.Id - this could be the assembly version (which we can also set)
    • [x] Usage of the AppxManifest.xml file - this does not exist in unpackaged and all checks should assume it is declared/correct
    • [ ] Add tests to validate all publishing scenarios
    • [x] #8432
  • [ ] Some Essentials APIs are not working as expected: #8552

Related Issues

  • https://github.com/microsoft/WindowsAppSDK/issues/2456
  • https://github.com/microsoft/WindowsAppSDK/issues/2032
  • https://github.com/microsoft/WindowsAppSDK/issues/2684
  • https://github.com/dotnet/maui/issues/7170

mattleibow avatar Oct 28 '21 19:10 mattleibow

@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 avatar Feb 12 '22 01:02 mattleibow

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

mattleibow avatar Mar 08 '22 20:03 mattleibow

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

mattleibow avatar Mar 17 '22 15:03 mattleibow

@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 avatar Mar 17 '22 17:03 javiercn

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

javiercn avatar Apr 07 '22 16:04 javiercn

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

mattleibow avatar Apr 07 '22 20:04 mattleibow

@mattleibow reopened this 5 minutes ago

Oops, sorry!

Eilon avatar Apr 11 '22 20:04 Eilon

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

DanJBower avatar Apr 28 '22 19:04 DanJBower

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.

mattleibow avatar Apr 29 '22 06:04 mattleibow

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

DanJBower avatar Apr 29 '22 09:04 DanJBower

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

mattleibow avatar Jun 28 '22 13:06 mattleibow

@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.

javiercn avatar Jun 28 '22 13:06 javiercn

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.

mattleibow avatar Jul 01 '22 13:07 mattleibow

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.

mprogers avatar Aug 21 '22 21:08 mprogers

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.

haslingerm avatar Sep 14 '22 06:09 haslingerm

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

MagicAndre1981 avatar Sep 14 '22 07:09 MagicAndre1981

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.

haslingerm avatar Sep 14 '22 09:09 haslingerm

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

mattleibow avatar Oct 07 '22 08:10 mattleibow