The newest release brings support for .NET 6 (for iOS, Android, mac Catalyst and macOS), support for Visual Studio 2022 templates, WinAppSDK 0.8.1, Focus management updates, a XAML Trimming feature to reduce the size of WebAssembly apps by nearly 50% as well as many other improvements and bug fixes.
WinUI Everywhere
In order to follow through on our vision to make WinUI-built applications everywhere, we remain in lockstep with all advancements in Windows developer ecosystem. As Microsoft announced, WinUI 3 now ships as part of the new WinAppSDK (formerly known as Project Reunion). WinAppSDK 0.8.1 has been released and our 3.9 release supports it.
.NET 6 support – iOS, Android, macOS Catalyst and macOS
Adding support for .NET 6 mobile targets required a significant effort in terms of packaging to ensure that both current Xamarin (iOS/Android/macOS) targets are supported, as well as new .NET 6 based targets. This new support is available for both Uno.UI and Uno.WinUI packages, ensuring a smooth transition for existing projects.
.NET 6 Mobile for Uno Platform support comes with iOS, Android, macOS (AppKit) and Catalyst targets. Mac Catalyst is the newest platform addition, giving the ability for UIKit-based apps to run on macOS with minimal modifications. macOS through AppKit is also available, in the same way Xamarin.Mac provided that support.
The move to .NET 6 means that the simpler SDK-style projects are used for most targets (except UWP, more on this below). This allowed us to merge all mobile targets into one project. You’ll notice that these new templates are still using “shared projects” as Web and Skia projects still cannot be merged into the main project.
Note that as .NET 6 is currently in preview, the Uno Platform support is also available in preview and we’ll talk about that more later on in this post.
Visual Studio 2022
Immediately after the first preview was announced, we were able to confirm that Uno Platform projects are supported. We blogged about the significantly improved solution load times we experienced, as well as the performance of C# Hot Reload and the feasibility of working with our Skia/GTK heads.
As of today, we take the support for Visual Studio 2022 preview 2 further by providing solution templates. This enables you to seamlessly start new Uno Platform projects from Visual Studio 2022. We will monitor the progress of Visual Studio 2022 Previews closely and ensure that we are ready as soon as a stable release is available.
Our Visual Studio extension is available in preview and can be found in the marketplace.
The extension provides two .NET 6 enabled templates, one for Uno Platform cross-platform applications, and another one for cross-platform libraries. More templates can be found with our dotnet new templates documentation.
Experimenting with .NET 6 projects
An up-to-date documentation of this content is available here.
Setting up the environment
First, a few requirements to use .NET 6 projects:
- .NET 6 preview 6 or later
- Visual Studio 2022 preview 2 on Windows
- xCode 13 beta 2 or later on mac to run iOS/macOS/Catalyst apps
We’ve updated the uno.check tool to ease the installation of the many dependencies required to build .NET 6 apps.
To install the uno-check tool:
dotnet tool install -g Uno.Check –version 0.2.0-dev.166
If a later version is available, you can use it instead of 0.2.0-dev.166
Run the uno-check tool:
uno-check –preview
Follow the steps and suggestions from the tool to get your environment setup.
Creating the projects
Once done, you can create a .NET 6 app in two ways:
- Using the Visual Studio 2022 extension, with the cross-platform application template, on Windows
- Using the dotnet new templates, on Windows and macOS
For the VS 2022 extension, use the file – new project experience and create a project.
For dotnet new, do the following to install or upgrade the templates to Uno Platform 3.9:
dotnet new -i Uno.ProjectTemplates.Dotnet
Then create a new project (UWP):
dotnet new unoapp-net6 -o MyUnoApp
or with the WinAppSDK APIs (WinUI 3):
dotnet new unapp-winui-net6 -o MyUnoWinUIApp
Debugging the apps
Depending on the targets, the debugging may not be available yet as part of Visual Studio 2022 for Windows. .NET 6 projects are not yet supported by Visual Studio for mac.
For Android:
- VS2022 for Windows is supported:
- In the “Debug toolbar” drop down, select framework net6.0-android
- Select an active device in “Device” sub-menu
- On mac, you can deploy the app to a device or simulator using the following :
-
dotnet build MyUnoApp.Mobile -t:Run -f net6.0-android
-
For iOS, mac catalyst and mac:
- Visual Studio 2022 for Windows is not supported yet (as of Preview 2)
- On mac, your can deploy your app to a simulator using the following :
-
dotnet build MyUnoApp.Mobile -t:Run -f net6.0-ios
-
dotnet build MyUnoApp.Mobile -t:Run -f net6.0-maccatalyst
-
dotnet build MyUnoApp.Mobile -t:Run -f net6.0-macos
-
The .NET team is working very hard on making those debugging experiences great, and we expect to see improvements in upcoming releases of Visual Studio for mac and Windows.
Keyboard and programmatic focus
Uno Platform 3.9 brings the first release of keyboard focus management to all targets. You can now use Tab and Shift+Tab to move keyboard focus between elements of your app or even set up directional XY focus using arrow keys. On Android and iOS, keyboard focus is experimental for this release, but can be enabled manually (see our Focus Management documentation). In addition, programmatic focus is now fully supported across all targets with the same behavior everywhere. For full documentation, see the Programmatic focus navigation with keyboard, gamepad, and accessibility tools here.
For more information, watch this video on Focus management for Android below.
XAML Resources Trimming
Application payload size is a particularly important metric, and recent improvements in the .NET linker have given us the ability to improve our tooling.
We’re introducing a feature called XAML Resources Trimming, which allows to reduce the uncompressed size of an AOT (Ahead of Time) compiled WebAssembly application by 50%.
For instance, using a blank Uno Platform application:
To enable XAML Resources trimming, add the following block to your WebAssembly project:
<PropertyGroup> <UnoXamlResourcesTrimming>true</UnoXamlResourcesTrimming> </PropertyGroup>
This feature will be available in the future for other targets that are using .NET 6.
Give it a go and let us know how XAML Trimming fares in your application!
Under the hood
Internally, Uno Platform generates C# from XAML, which in turn gets translated to native code for the target platform. The standard trimming process is able to remove a lot of unused code in an application using static reference detection, but fails when string-based switching is used.
This kind of string-based switching is used a lot in XAML, particularly when dealing with styles. For example, creating a control with a default style creates a piece of code that generates a switch/case pattern that the linker cannot find. This forces the code for the style and the control to be kept in the application even it it’s not used, increasing the app payload.
The XAML Trimming tooling uses the .NET 6 IL Linker substitution feature multiple times to determine which pieces of code are used, therefore removing many styles and controls that are not used in applications.
You’ll notice in the chart above that the proportion of IL removed is smaller that the proportion of WebAssembly code that was removed. This indicates that not all code has the same generated weight, making trimming particularly useful.
We will continue making improvements to this feature in the future, to further trim down the size of applications.
NuGet Package Explorer on the Web
While this isn’t officially a part of our release, it is worth highlighting that you can now access NuGet Package Explorer via https://nuget.info – all powered by Uno Platform.
Other significant updates
We’ve closed many other issues and added other features, and as always thanks to our contributors!
-
- Detection of Uno.UI and Uno.WinUI mixing (@workgroupengineering)
- FileOpenPicker Settings identifier (@pkar70)
- VS2022 template .NET 6 fixes (@LeftTwixWand)
- Clipboard support for GTK and WPF (@trungnt2910)
- Enumeration of ApplicationDataContainer (@DZetko)
- Color.ToString() updates (@VitezslavImrysek)
- GetNetworkConnectivityLevel for WPF (@ahoefling)
- Linux installation documentation (@baskren)
- Animated Icon support (MartinZikmund)
- WinUI ImageIcon (MartinZikmund)
- Roslyn based source generation error reporting improvements (@jeromelaban)
- CachedFileManager support (MartinZikmund)
- Shapes rendering performance improvements (@carldebilly)
Next Steps
To upgrade to latest release of Uno Platform, please update your packages to 3.9 via your Visual Studio NuGet package manager! If you are new to Uno Platform, the best way to get started is to follow our official getting started guide.(5 min to complete)
About Uno Platform
For those new to Uno Platform – it allows for creation of pixel-perfect, single-source C# and XAML apps which run natively on Windows, iOS, Android, macOS, Linux and Web via WebAssembly. Uno Platform is free and Open Source (Apache 2.0) and available on GitHub.