Hands On: .NET MAUI Desktop, Hot Reload, Blazor WPF/WinForms Controls in .NET 6 Preview 3

Microsoft's .NET MAUI (Multi-platform App UI) is the next-gen evolution of the mobile-centric Xamarin.Forms that adds desktop app support, which has just been formally introduced in .NET 6 Preview 3.

Microsoft's David Ortinau updated developers on what's new for .NET MAUI, with the very first heading in his April 9 post reading: "Windows Desktop Now Supported."

"Project Reunion 0.5 has shipped!" said Ortinau, principal program manager. "Now Windows joins Android, iOS, and macOS as target platforms you can reach with .NET MAUI! To get started, follow the Project Reunion installation instructions. For this release we have created a sample project that you can explore and run from the 16.10 preview of Visual Studio 2019."

Much of the post details how to get started to build a desktop app, with Ortinau providing this graphic of the result:

.NET MAUI and WinUI 3
[Click on image for larger view.] .NET MAUI and WinUI 3 (source: Microsoft).

This reporter (a hapless and hopeless amateur) followed the aforementioned Project Reunion setup instructions and used Get started with WinUI 3 for desktop apps along with Templated XAML controls for WinUI 3 apps with C# guidance to cobble together a WinUI 3 example that looks similar in that they both have a "WinUI Desktop" label in the top-left corner:

WinUI WPF Desktop App
WinUI Desktop App

Doing the same with .NET MAUI, though, was beyond my reach.

Granted, I probably code less than 10 hours a year, and then mostly just to quickly try something out for an article. This time, I found the aforementioned .NET 6.0.0 Mobile Samples documentation confusing about the desktop side of things.

For example I found the following on that site:

  • Under a "WINUI3" heading is this:
    "Currently WinUI3 requires build and deploy. You will need to open the HelloWinUI3.sln with the latest preview of Visual Studio 2019 16.10."
  • Under the "HelloWinUI3 - .NET MAUI WinUI3 application" project is this:
    "WinUI3 requires build and deploy with the latest preview of Visual Studio 2019 16.10."
  • Under a "Using IDEs" heading is this:
    "IDE integration into Visual Studio, Visual Studio for Mac, and Visual Studio Code are a work in progress."
  • Under a ".NET MAUI" heading is this:
    ".NET MAUI bassed projects can be open in Visual Studio and Visual Studio for Mac, however can not be run or debugged directly from the IDEs at this time."

These items appear to be contradictory. Can you use Visual Studio or not? Do you use it to build and deploy (I could build but not deploy) and then run it from the CLI? If anyone knows, please share in the comment section below.

Anyway, I tried a bunch of different things. I opened the HelloWinUI3.sln with the latest preview (as advised above) but couldn't get it to work. I tried setting HelloWinUI as the startup project and HelloMaui as the startup project, but both failed. Here a just a couple of the myriad errors I encountered in five hours of frustration:

One of a multitude of errors
[Click on image for larger view.] One of a multitude of errors
One of a multitude of errors
[Click on image for larger view.] Another error

The Android example did appear to work, though I didn't want to bother with installing HAXM hardware acceleration for the Android simulator and it thus ran so slowly I never found out, being more interested in the new desktop support.

Anyway, I'm not the only one confused about all this stuff, as expert programmer and former Visual Studio Magazine contributor Nick Randolph noted early this year in a post titled "WinUI 3.0 Misconceptions":

I wish I had a single place I could point developers wanting to understand the dysfunctional state of play between the various Microsoft teams: Maui, WinUI, Project Reunion, dotnet etc.

Amen, brother. I know Microsoft is trying to clear things up.

Anyway, on the brighter side of things, I also tried out other new goodies announced last week as part of .NET 6 Preview 3.

For example, the new Hot Reload functionality for Blazor (and eventually everything else) worked fine, though it required CLI operations with dotnet watch, not working in the IDE yet.

I also tried out new Blazor WebView controls for WPF and WinForms, announced in this post (which also announced Hot Reload).

I couldn't get the WinForms example to work because I didn't know where to insert some code for the BlazorView control that was provided in the announcement post. I did get WPF to work, though.

One of a multitude of errors
[Click on image for larger view.] Blazor WebView WPF Control

I also tried out WPF Hot Reload and it seemed to work, but I noticed that, upon a code change and file save, the existing window didn't just update -- it seemed to disappear and then reappear under other windows I had open. I thought it had just quit until I noticed that new window in the taskbar. I don't know if that's considered real Hot Reload or not.

All in all, Microsoft seems well on the way to a successful huge milestone .NET unification effort with .NET 6 in November, where all these things will hopefully coalesce into a common experience from within Visual Studio (because if I can do this stuff, anyone can do this stuff). Many more previews are to come, each implementing new features and functionality.

And again, if anybody can point to good-for-noobs guidance to get a .NET MAUI/WinUI 3 desktop app to work, let me know below. I'm sure it's easy for real developers.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus


Subscribe on YouTube