The .NET framework is a versatile and powerful platform for building a variety of applications, including web, desktop, mobile, cloud, gaming, and IoT applications. With the release of .NET 8, Microsoft has introduced several enhancements and features that make it even more appealing for developers.
.NET is a free, cross-platform, open-source framework that supports multiple programming languages, allowing developers to build applications for Windows, macOS, and Linux. It consists of a runtime (Common Language Runtime or CLR), a set of libraries, and development frameworks.
What is .NET MAUI?
.NET MAUI is designed to simplify cross-platform application development by allowing developers to create native apps using a single codebase. With .NET 8, MAUI introduces new features and improvements, making it an exciting choice for building modern, multi-platform applications.
Kay features of .NET8 can be found here.
Before you begin, ensure that you have the following installed on your development machine:
- Visual Studio 2022 or Visual Studio Code
- .NET SDK 8.0
Additionally, you need to have .NET Multi-platform App UI workload to be installed in your machine.
Creating a .NET MAUI Project
Now, let’s get started with creating .NET MAUI with .NET8. In this article we will use Visual Studio 2022 to create .NET MAUI application. Alternatively, you can use Visual Studio code as well.
Step 1 – Open Visual studio 2022 and create new project.
Step 2– In this step, you will see different categories of MAUI such as . NET MAUI App, .NET MAUI Blazor App, .NET MAUI Class Library.
.NET MAUI App: Using this we can develop applications for iOS, Android, Mac Catalyst, macOS, Tizen, and Windows from a single code base.
.NET MAUI Blazor App: This option is for MAUI app development using Blazor and these applications are able to run in iOS, Android, Mac Catalyst, macOS, Tizen, and Windows.
.NET MAUI Class Library: This is for building a class library using .NET MAUI which is able to run in Android, iOS, Mac Catalyst, macOS, Tizen, and Windows.
However, we will select project template .NET MAUI App and click on Next button as depicted below.
Step 3 – Configure your project, give the project name, location, and click on Next as shown below.
Step 4– Select framework .NET 8 (long-term support) as portrayed below and click on Create.
It takes a few seconds to create a project and install dependencies wait for it.
Step 5 – Once it is created, we ca see the project structure as shown below.
Now, the project is created we can run and check it.
Step 6 – In this article we will run this project using an Android Emulator. So, for this, in Visual Studio toolbar we need to select Android Emulator in Debug target as illustrated below.
Exploring the Project Structure
A .NET MAUI project has a structure similar to other .NET projects, with platform-specific folders for Android, iOS, macOS, and Windows. Key files include:
MainPage.razor: The main UI component written in Razor syntax.
App.xaml/App.xaml.cs: The application entry point where you can configure app-wide settings.
MauiProgram.cs: The entry point for the application where the MauiProgram class is defined.
Step 7– Then Visual Studio will ask you to create a Default Android device as shown below. Click on Create button.
Then accept the License.
Step 8– Close Android Device Manager window.
Step 9– Select Pixel 5 – API 34 (Android 14.0 – API 34) in debugger and run the app.
In a nutshell, with .NET MAUI, building cross-platform native apps becomes more straightforward and efficient. In this article we learned what MAUI is, it’s uses and benefits, and the types of MAUI application development. Additionally, we created a .NET MAUI application, got familiar with it and ran it for Android device. Furthermore, you can explore the features, experiment with the code, and leverage the power of .NET 8 to create modern applications for a wide range of devices.