Skip to footer content
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.

The .NET Framework supports building and running .NET applications specifically for Windows, providing a robust environment for desktop, web, and server applications. In contrast, .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

.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 of .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 of .NET MAUI, explaining that it stands for Multi-Application User Interface, enabling applications to run on various platforms, including Android, iOS, macOS, Windows, and Tizen, all 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:

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

  2. 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.

    Exploring Dotnet Maui Cross Platform Capabilities And Compatibility 1 related to Creating a New .NET MAUI Project

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

    Exploring Dotnet Maui Cross Platform Capabilities And Compatibility 2 related to Creating a New .NET MAUI Project

  4. 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 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.

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.

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.

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 to include platform-specific code.

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, showing how XAML is used for the UI and C# for the code-behind.

Running Applications on Multiple Platforms

Testing .NET MAUI applications across multiple platforms is essential to evaluate performance and appearance. Tim emphasizes testing on a Windows machine, an Android emulator, and on iOS devices with an Apple developer account.

Setting Up Development Environments

Tim outlines the need for different setups depending on the platform. For Android, install Android emulators. For iOS, an Apple developer account is necessary, costing approximately $100 per year.

Enabling Developer Mode for Windows

Activating developer mode on Windows is essential for testing .NET MAUI applications, allowing for sideloading apps without the Microsoft Store.

Exploring Dotnet Maui Cross Platform Capabilities And Compatibility 3 related to Enabling Developer Mode for Windows

Testing on Windows

Tim demonstrates testing a .NET MAUI app on a Windows machine, utilizing the hot reload feature to make changes to the application code and see updates in real-time.

Exploring Dotnet Maui Cross Platform Capabilities And Compatibility 4 related to Testing on Windows

Testing on Android Emulator

Tim uses the Galaxy Nexus emulator running Android 12 to test, explaining the process of starting the emulator, installing, and launching the application.

Exploring Dotnet Maui Cross Platform Capabilities And Compatibility 5 related to Testing on Android Emulator

Comparison of Windows and Android Versions

Tim compares the application on both platforms, noting functionality consistency despite appearance differences.

Exploring Dotnet Maui Cross Platform Capabilities And Compatibility 6 related to Comparison of Windows and Android Versions

Future of .NET MAUI and Xamarin

.NET MAUI is fully supported by Microsoft, expected to receive ongoing improvements. As its successor, 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 capabilities. His video is a valuable resource for developers eager to explore this framework. For deeper dives and practical coding examples, visit his YouTube channel IAmTimCorey and check out more resources available at iamtimcorey.com.

Hero Worlddot related to Exploring .NET MAUI cross-platform capabilities and compatibility
Hero Affiliate related to Exploring .NET MAUI cross-platform capabilities and compatibility

Earn More by Sharing What You Love

Do you create content for developers working with .NET, C#, Java, Python, or Node.js? Turn your expertise into extra income!