Iron Academy Logo
C# Framework

Exploring .NET MAUI cross-platform capabilities and compatibility

Tim Corey
37m 50s

Building cross-platform applications is a fundamental skill for modern developers, and understanding the core underlying project structures is essential.This article, inspired by Tim Corey's video on ".NET MAUI First Look - What is it, how do we use it, and is it ready" dives into the complexities of building cross-platform apps using the .NET MAUI framework.

.NET Framework supports building and running .net applications specifically for Windows, providing a robust environment for desktop, web, and server applications, while .NET MAUI extends this capability to cross-platform development using .NET implementation, allowing you to create applications that run on Windows, Android, and iOS with a unified code base.

By following Tim’s insights, we will explore how to set up, configure, and optimize this software development framework, utilizing the full potential of .NET MAUI to build efficient and maintainable mobile and desktop applications.

Introduction to .NET MAUI

As of now, .NET MAUI is a cutting-edge cross-platform framework within the .NET ecosystem, enabling developers to create applications for Android, iOS, macOS, and Windows using managed code. It leverages the comprehensive .NET framework class library and common language runtime (CLR) for efficient performance across different operating systems.

.NET MAUI's modular and optimized architecture supports various programming languages, including C# and Visual Basic. Integrated seamlessly with Visual Studio, it ensures efficient .NET development, backed by the .NET Foundation and an active community net developers.

This framework embodies the future of .NET development, offering cross-platform compatibility for web, desktop, and mobile applications. With its ability to compile .NET code into machine code and support for application model frameworks like WPF and Windows Forms, .NET MAUI is a versatile and powerful tool for modern net application developers.

Understanding .NET MAUI and Its Components

Tim also gives an overview about MAUI and explains that MAUI stands for Multi-Application User Interface, enabling applications to run on various platforms, including Android, iOS, macOS, Windows, and Tizen programmed under a single programming language. However, Linux is not currently supported. He elaborates on the successor role of .NET MAUI to Xamarin and how it consolidates different .NET Core and .NET Framework flavors under .NET 6.

Setting Up .NET MAUI in Visual Studio

Tim demonstrates setting up a .NET MAUI project using the preview version of Visual Studio since .NET MAUI had not yet been released at the time of the video. He highlights the slight differences in the preview version and mentions the stability of the release candidate bits.

Creating a New .NET MAUI Project

To start, Tim Corey demonstrates how to set up a new .NET MAUI project. Here are the steps outlined in his video:

  • Open Visual Studio: Start by opening Visual Studio and selecting the option to create a new project.

  • Choose the MAUI Template: From the project templates, select ".NET MAUI App," ".NET MAUI Blazor App," or ".NET MAUI Class Library" and click Next. Tim uses .NET MAUI App. \ (All information in image needed or can zoom in?)

  • Configure Project Settings: Enter the project name, choose the location, and solution name.

  • Create the Project: Click "Create" to generate the project with the default configurations and necessary code.

This setup provides a foundation for exploring cross-platform development, with Visual Studio generating a basic structure that includes essential components like MauiProgram.cs, platform-specific folders, and shared resources.

Examining the Project Structure and .NET Platform MAUI Code

Tim explores the project structure, pointing out similarities to WPF and WinUI projects.

XAML Familiarity

Tim highlights that .NET MAUI uses XAML for design, similar to WPF and WinUI projects. For those new to XAML, it will look familiar, but there are some differences.

Project Structure

Tim explains the structure of MauiProgram.cs, noting it includes the use of a static class MyProgram with an entry point CreateMauiApp. This is similar to other .NET projects, with configurations for fonts, dependency injection, and logging.

Target Frameworks

The project targets multiple frameworks: .NET 6 for Android, iOS, macOS (Catalyst), and Windows. It supports Windows 10 (version 19041 and above) and Windows 11, but not older versions of operating system like Windows 7, XP, or Vista.

Conditional Builds and Platforms

Tim explains the use of conditional statements in the project file to handle multiple frameworks, separated by semicolons. This allows targeting specific platforms and managing platform-specific dependencies.

Platform-Specific Code

Folders for each platform (Android, iOS, macOS, Tizen, Windows) manage platform-specific code. Developers can exclude platforms by removing the respective targets and folders from the project file.

Build Process and Abstraction

.NET MAUI abstracts much of the platform-specific work, compiling the code to use each platform's APIs. This ensures a native look and feel for each platform. However, developers might need to tweak specific elements for different platforms.

Configuration and Assets

Tim covers configuration files like AndroidManifest.xml and Info.plist for iOS, which handle platform-specific settings. GUI tools are available for easier editing of these files, especially on iOS.

Exploring Platform-Specific Features

Tim highlights the importance of platform-specific features and how .NET MAUI handles them. He discusses the Platforms folder, which contains subfolders for each supported platform. Each subfolder includes platform-specific code that can be customized as needed, allowing developers to leverage unique features of each platform.

Shared Project Files

Tim then explores the shared project structure, explaining how the shared code is written once and runs on multiple platforms. He illustrates this by examining the MainPage.xaml and MainPage.xaml.cs files (18:00). Tim also shows how XAML is used for the UI and C# for the code-behind, emphasizing the reusability and flexibility of this approach.

Running Applications on Multiple Platforms

Tim Corey discusses the importance of testing .NET MAUI applications across multiple platforms to evaluate their performance and appearance in various environments. He emphasizes that this includes testing on a Windows machine, which allows for checking different Windows versions, as well as utilizing an Android emulator to simulate an Android phone on your computer. Additionally, testing on iOS devices is necessary, which requires an Apple developer account to run the application on physical iOS devices.

Setting Up Development Environments

In his explanation, Tim outlines the need for different setups depending on the platform you are targeting. For Android testing, he notes that Android emulators need to be installed, and he has already set up his own emulators. For iOS testing, you need an Apple developer account, which costs approximately $100 per year. Tim points out that testing on iOS devices can be more complex if you are using a Windows machine, highlighting the additional steps required to test effectively on iOS.

Enabling Developer Mode for Windows

Tim elaborates on the necessity of enabling developer mode on Windows for testing .NET MAUI applications. Activating developer mode is essential as it allows for side-loading apps, which bypasses the default installation process through the Microsoft Store. He advises caution when sideloading apps from unknown sources, emphasizing the importance of ensuring that the apps you sideload are safe and secure. (Need full screen or can zoom in? Image can be better quality also).

Testing on Windows

Tim provides a demonstration of testing a .NET MAUI app on a Windows machine. After enabling developer mode, the application is installed on the machine. Here is the screenshot of the application:

Then at 24:04, he highlights the hot reload feature, which allows developers to make changes to the application code and see updates in real-time without needing to restart the application. This feature significantly enhances the software development, and testing workflow.

Testing on Android Emulator

Shifting focus to the Android emulator, Tim selects the Galaxy Nexus emulator running Android 12 for testing. He details the process of starting the emulator, installing the application, and launching it. Tim compares the performance and appearance of the app on the emulator with its Windows counterpart. He also demonstrates how the hot reload feature updates the application instantly on the emulator, showcasing the efficiency of this feature across platforms.

Comparison of Windows and Android Versions

Tim compares the application as it runs on both Windows and Android platforms. He notes that while the app may appear slightly different on each platform, its core functionality remains consistent. (Can image on left be as clean as image on right?)

This comparison illustrates .NET MAUI’s capability to support a single code base that operates across different platforms, effectively demonstrating its cross-platform capabilities.

Future of .NET MAUI and Xamarin

Looking ahead, Tim provides insights into the future of .NET MAUI and Xamarin. He affirms that .NET MAUI is fully supported by Microsoft and is expected to receive ongoing improvements, making it a viable option for new projects. However, at 33:39 he also notes that significant changes are anticipated in the coming months. As for Xamarin, Tim explains (36:05) that .NET MAUI is its successor, and existing Xamarin projects can be upgraded to .NET MAUI, ensuring a smooth transition for developers.

Conclusion

Tim Corey provides a comprehensive overview of .NET MAUI, its setup, and its capabilities. His video serves as a valuable resource for developers eager to explore this new cross-platform framework. For those interested in deeper dives and practical coding examples, check out his YouTube channel IAmTimCorey.

For more detailed tutorials and advanced topics in .NET MAUI, Tim Corey recommends exploring his courses and additional resources available at iamtimcorey.com.