Cross-Platform Mobile Development With .NET MAUI – The Next Big Tool For Creating Apps
Table of contents
- About .NET MAUI
- Who Is .NET MAUI For?
- How Does .NET MAUI Work?
- How .NET MAUI Compiles Into Native App Formats/Packages
- Components Of .NET MAUI
- Single Project Feature
- Cross-Platform APIs For Device Features
- Hot Reload Feature
- How .NET MAUI Replaces Xamarin
- Modern-View-Update And Blazor Patterns
- Migrating From Xamarin To .NET MAUI
- .NET MAUI Support And Xamarin Continuity
The move by Microsoft to unify its various multi-platform development technologies started with .NET 5. These multi-platform technologies included frameworks such as the .NET Core, .NET Mono, and Xamarin, with .NET 5 serving as the support base and unified ecosystem to manage them all.
However, Microsoft wishes to take this unification further by introducing .NET 6, and more particularly, the more developed .NET MAUI. What exactly does .NET MAUI present to developers and how is it different from its counterparts?
This article presents you with all you need to know about .NET MAUI, including
- Who .NET MAUI is for,
- Components of .NET MAUI, and
- Difference between .NET MAUI and Xamarin. Let’s get right in.
About .NET MAUI
MAUI is an abbreviation for Multi-platform App UI, and this almost makes it self-explanatory. .NET MAUI is a multi-platform UI framework for developing apps across multiple mobile and desktop operating systems.
These operating systems include Windows, iOS, Android, macOS, and Samsung’s Tizen operating system, and .NET MAUI provides a single-code base that compiles all the codes needed to build apps across them. This new Microsoft platform works through the use of C# and XAML.
.NET MAUI is open-source, additionally provides developers with web view controls to natively run Brazor components, and allows users to add platform-specific codes and resources to build their apps.
If you have previously made use of Xamarin.Forms, .NET MAUI would present you with some level of familiarity. However, you get extended mobile and desktop scenarios, as well as UI controls that have been revamped for better performance and compatibility reach.
Who Is .NET MAUI For?
.NET MAUI is a single-code framework suitable for any type of application developer. However, professionals that have been yearning to have a single-code base to build cross-platform applications will particularly find it more useful and satisfactory.
If you write applications using XAML and C#, then the platform is a perfect fit for you, as there is a little learning curve to go past. .NET MAUI is also great for developers that want shared UI and design tools, shared codes, shared test actions, and shared business logic for building apps across multiple operating systems.
Overall, .NET MAUI is an open-source framework from Microsoft that presents developers with a single platform to create multi-platform applications while retaining certain similarities with previously deployed technologies.
How Does .NET MAUI Work?
.NET MAUI works by combining APIs of Windows, iOS, macOS, and Android into a single API. This single API works with its specific set of codes (C# and XAML), and these specific codes are used to create applications that run on any of the compatible operating systems.
More specifically, .NET MAUI comprises/provides developers with a combination of platform-specific frameworks. These frameworks include .NET for iOS, .NET for macOS, .NET for Android, and .NET for Windows UI 3 library.
You write C# and XAML codes compatible with the .NET MAUI API, and the API directly interacts with these native framework APIs to create your apps and UI elements. This is opposed to the .NET 6 Base Class Library (BCL) that needs a bridge such as the .NET Mono runtime to interact with these frameworks.
Rather than using separate runtimes to create execution environments for your APIs, .NET MAUI interacts directly with these APIs. This means that, when it comes to .NET 6, .NET MAUI is the truly single-platform code-base that seamlessly centralizes all your application development workflows.
How .NET MAUI Compiles Into Native App Formats/Packages
.NET MAUI runs on a single-code framework to allow multi-platform compatibility and a unified development process. However, to run on the native operating systems and devices, these codes need to be specifically compatible with them.
This means, for example, .NET MAUI codes are compiled into .apk packages for Android OS or .exe packages (among others) for Windows OS. Now, although they use the same .NET codes, each operating system has its specific processes for compilation.
For Android OS, the C# codes are compiled into Intermediary Language (IL), which is then compiled into a native assembly during launch (JIT). Windows apps, on the other hand, are compiled using the Windows UI 3 library.
Unlike the JIT (Just-In-Time) compilation for Android which takes place during launch, iOS implements AOT (Ahead Of Time) compilation where the C# codes are compiled into ARM assembly code way before launch. macOS apps are built using a Mac Catalyst integration. You need a Mac to build both iOS and macOS apps using .NET MAUI.
Components Of .NET MAUI
.NET MAUI presents you with certain features and components that help to facilitate this cross-platform development process. These components span across usage in data visualizations, monitoring, and user actions.
The framework fosters a fast development process as it offers you reusable UI components from vendors like Syncfusion, UX Divers, and DevExpress, among others. You have access to a comprehensive engine to design web pages from scratch, as well as page templates for creating multiple pages and navigation types.
Data-binding is supported, and you also have access to handler customizations to improve visualizations of UI elements.
.NET MAUI additionally comes with cross-platform graphics functionality, which is a canvas that covers all graphics design operations. You draw and paint objects, transform existing objects to how you please, and also engage in compositing operations.
Single Project Feature
Regardless of all mentioned above, however, a few components prove to be more useful and influential to the development process within .NET MAUI. These are the single project feature, Cross-Platform APIs for device features, and the hot reload feature
The single project feature connotes everything we have talked about concerning cross-platform development compatibility. However, a few additional features have not been mentioned.
These include a simplified debug mode for testing .NET MAUI apps, shared access to file resources, and a shared cross-platform entry point.
The single-platform characteristic also presents developers with simplified and centralized access to platform-specific tools and APIs. These are tools that a user may need to perfect the development process on a particular operating system or platform.
English and German
Cross-Platform APIs For Device Features
Device features here relate to the features within the .NET MAUI API that allow the application you develop to interact with certain components of the device it is installed on. These features number up to 60 and are available directly through the C# code.
For instance, the API allows you to develop applications with access to device sensors like accelerometers and gyroscopes. With the API, the application is also granted access to device connectivity status, as well as other information about the device.
.NET MAUI additionally supports developing applications that interact with system clipboards, dig into device files, safely store data, and even have access to built-in text-speech engines.
Hot Reload Feature
Here is a .NET MAUI feature that noticeably helps with faster and more seamless workflows. XAML and C# Hot Reloads connote the ability to make changes to the app without having to recompile its codes.
While the app is running, .NET MAUI lets you make and save changes to XAML and C# codes, and see how these changes reflect within the app UI in real-time.
This helps with quick and accurate debugging, and also gives you a chance to test new features within Visual Studio.
How .NET MAUI Replaces Xamarin
As mentioned earlier, .NET MAUI is an evolution from the Xamarin.Form framework, and it shares several similarities with it. These similarities are mainly concerned with the cherished XAML controls. However, .NET MAUI is regarded as an improvement over Xamarin for a number of reasons.
Xamarin, just like .NET BCL, makes use of Mono Runtime as a bridge to interact with the different OS frameworks. .NET MAUI, instead, interacts directly with these frameworks and offers developers a faster workflow.
Improvements in the balance between app performance and size also make .NET MAUI optimized for speed. You load up applications faster compared to Xamarin when you use .NET MAUI JIT compilation, and even two times faster with AOT compilations.
You also easily create accessible applications with integrated screen readers and automations for example, and reduce clutter in your files through Global Statements and File-scoped Namescapes.
Modern-View-Update And Blazor Patterns
Unlike Xamarin which only supports Modern-view-Viewmodel and Reactive UI patterns, .NET MAUI additionally supports Modern-View-Update (MVU) and Blazor development patterns.
Blazor particularly helps with adaptive programming models and lets you create hybrid applications. With .NET MAUI, it allows developers to create applications for desktop and mobile platforms with additional integrated web-based rendering.
Through the Unified SDK, developers easily reuse the same design and UI components across mobile, desktop, and web-app models. The Blazor development pattern also gives developers a chance to take advantage of device and platform components like Bluetooth, geo-location, and notifications, among others.
Slim renderers within .NET MAUI, as opposed to custom renderers in Xamarin.Form, make your application lighter and allow for even more seamless development processes. .NET MAUI also allows you to manage all design elements like fonts, images, and app icons, among others, from the same resource folder.
Migrating From Xamarin To .NET MAUI
.NET MAUI is innately integrated with .NET 6. Xamarin.Form, on the other hand, runs on .NET Core 3.1 and it is understandable if you expect difficulties converting or migrating Xamarin apps into the .NET MAUI framework. It isn’t as hard as you may expect.
The easiest method is to use the Microsoft Upgrade Assistant tool. This allows you to easily migrate your Xamarin apps into .NET MAUI.
Alternatively, you may manually migrate your Xamarin apps by following these steps
- Convert apps from the .NET framework to .NET SDK format,
- Make changes to namescape,
- Make appropriate changes to NuGet packages,
- Debug bad API changes, and
- Test the newly developed app to see if it works properly.
Whichever method you choose, at least you don’t have to write new C# or XAML codes to create a .NET MAUI application that mimics exactly what your Xamarin app does. Microsoft presents a guide to converting your Xamarin apps to .NET MAUI applications.
.NET MAUI Support And Xamarin Continuity
Upon its full release in May 2022, .NET MAUI will be supported and serviced monthly for the first 18 months to make sure it runs up to expectations.
Xamarin is still regarded as an important framework to be merged with .NET 6, and there will be continued support for the framework. The Xamarin team released an updated SDK that will be serviced alongside Xamarin.Forms up to 1 year after the release of .NET MAUI (estimated to end May 2023). After this period, all the focus will be shifted to .NET MAUI, .NET for Android, and .NET for iOS.
With .NET MAUI, you additionally enjoy support from a community of contributors from over 3,700 companies. This is more readily available through community members on Stack Overflow or within Microsoft’s Q&A platform. You may also visit .NET MAUI’s space on GitHub.
When it comes to .NET frameworks, the .NET 6 set of technologies presents you with the most seamless development processes within the ecosystem. However, with .NET MAUI, you get the most comfortable app development workflows yet, as you have a single-platform solution to build and manage all your cross-OS applications in one place.
.NET MAUI is the technology to get acquainted with if you just intend to start your journey in the .NET application development ecosystem.