Getting Started With .NET Maui
We’ve all been waiting with bated breath for the release of .NET Maui, Microsoft’s evolution of Xamarin.Forms. It was originally intended to ship as part of the .NET 6 releases but has proved incredibly complex to deliver. Finally, the wait is coming to an end. General availability is finally here. With that in mind, it’s finally time to get started with .NET Maui development, learn tips and tricks and move forward with your next cross-platform project.
Understanding .NET Maui
To deliver a cross-platform version of the .NET runtime, Microsoft first needed to update the core of .NET. This was a vital step to ensure code could run across Windows, macOS, Android, iOS and more. Then, the user experience needed a similar update, and this is where .NET Maui came into play.
.NET Maui stands for .NET Multi-platform App UI and is an evolution of the cross-platform development framework, Xamarin.Forms. The aim was to incorporate Windows and macOS desktop app support to the existing Android and iOS platform SDK support in Xamarin. Ultimately, .NET Maui has been created to give you the tools to build cross-platform apps for desktop and mobile and delivers some key advantages.
One of the core advantages of the evolution is that developers will be able to use C# language while maximising code sharing. What’s more, there are over featured layouts and controls for building adaptive UIs across both mobile and desktop platforms. Also, .NET Maui improves on Xamarin.Forms architecture by adding low-coce hooks for making modifications
The arrival of the GA version is an important milestone for .NET Maui as at this point in the software development life cycle, Microsoft is able to offer a go-live license. This means that code has moved from the test environment to the production environment and developers, consultants and companies can begin deployment to their applications.
Installing .NET Maui
Developers and consultants alike have been waiting for over five months now for production-ready .NET Maui tooling. Up to this point, preview releases were only intended for personal use to allow developers to learn new tools and techniques. While they could start porting code to new frameworks, they weren’t complete and were subject to change with subsequent releases. This all comes to an end with the latest RC version; the code is now frozen and further changes will be limited to bug fixes. What’s more, the go-live feature includes support and Microsoft is able to see interactions with real-world code and produce fixes.
The .NET Maui SDK is now API-complete, ready for libraries to update and prepped for imminent general availability. To access the RC version, developers need to install or update Visual Studio 2022 v17.2 Preview 3 and ensure that .NET Maui (preview) is checked under the Mobile Development with .NET workload during installation.
Getting Started with .NET Maui
Once you’ve installed the RC version of .NET Maui, it pays to have an idea of what you’re looking at and what you can achieve. First and foremost, if you’ve used Xamarin.Forms before, .NET Maui will feel very intuitive in the way it hosts OS-specific controls and UI elements in a single codebase. All code is in a single project to ensure there is no difference between the app across the different platforms while delivering a native look and feel and native controls. However, while Xamarin.Forms was only for mobile, .NET Maui delivers the support everyone has been waiting for for desktop environments.
.NET Maui offers a way to bring projects together, unifying .NET APIs that have up to this point been platform-specific. By doing this, C# and XAML code can be written once but run everywhere. .NET Maui sits above the native code and the common base-class libraries. To get the required platform APIs, code you write will call .NET Maui APIs. However, if you want to have native-specific features, you can call platform APIs directly. By using this approach, developers have a similar set of common controls to those used by Xamarin.Forms that allow UI code to scale accordingly for different devices and platforms.
To start building your first app, as we’ve touched on, you’ll need to configure Visual Studio to support .NET Maui mobile development. You’re then able to bring existing Xamarin apps across or to use .NET techniques to build apps from scratch. Projects are organised in a similar way to Xamarin.Forms with a single project holding all the code and platform-specific code. Once you’ve created a project, .NET Maui will automatically set up dependencies for your target operating systems. Android emulator and SDK will be installed and configured for you, but you’ll need to run a Mac alongside your PC on the same network to build iOS and macOS applications.
It pays to remember that .NET Maui has direct support from Microsoft, so there are no end of resources, tools and support available to developers. By using the latest Visual Studio preview release, you’ll have support for hot reload, an important debugging and development tool. The release notes on GitHub offer a huge amount of advice and the .NET Podcasts app can help jump start your journey by showcasing native app UI.
What’s Next for .NET Maui
While you might only want to build an app for one OS to start with, .NET Maui gives you the flexibility to expand in the future. You can simply take the code and use it across all other supported platforms with very little work. Ultimately, Microsoft is hoping that Maui will be the foundation for all your future .NET development.
Over the coming month, there will no doubt be lots of exciting projects in the pipeline as people get to grips with .NET Maui. Microsoft has already used it to build the .NET Podcasts sample application, which runs on Android, iOS, macOS and Windows, showcasing native app UI. General availability is expected around the time of Build 2022.