Getting Started With .NET Maui - First Impressions

Introduction

 
In changed world circumstances and dynamics, companies/organizations are bracing for digital transformation to increase the efficiency of their employees, products, and their services. In this pursuit of transformation, quicker Go To market is the key parameter in their success.
 
The advancements in handheld devices and their reliance in day today life has created a huge demand for smart applications and also there is an increased need in delivering them as fast as possible with buttery smooth experience without compromising on key features and Xamarin forms makes the obvious choice in this Arena(Flutter is still not stable and React native again a JavaScript).Xamarin forms has undergone 6+ years of development and with latest Xamarin form 5.0 it is the stable cross platform with jaw dropping User interfaces and seamless integration with native features.
 
Considering some drawbacks with Xamarin with existing state like having multiple platform specific projects and dependency on complex renderers, Microsoft has created new Platform .Net Maui also called multi platform app ui which aims at simplifying development by making unified project targeting .net 6 and created controls from scratch for performance. In this article let’s go through basic steps to create a simple Maui application.
 
Step 1
 
Maui application requires .net 6 preview latest version to be installed either as a standalone package or as part of Visual studio preview version. Microsoft team has created a command line utility to check and install required components for Maui application. Open Command prompt and type as shown below and follow onscreen instructions.
  1. dotnet tool install -g Redth.Net.Maui.Check  
 
Step 2
 
Now we will use a command to check for Maui prerequisites.In the same command prompt enter as shown below to check and install Maui dependencies and follow onscreen instructions. This might take a minute or two depending upon system speed.
  1. maui-check  
 
Step 3
 
Once Everything is installed create a folder in your favorite drive in the system and change to the created folder as shown below,
  1. C:/> mkdir MyMauiApplication  
  2. C:/> cd MyMauiApplication  
 
Step 4
 
Now its time to create a Maui application, in your command prompt enter as shown below,
  1. dotnet new maui  
 
Step 5
 
Now we have created the Maui application and it's time to see its contents. To do that let's open the application in VS code.
 
 
 
Step 6
 
In the VS code application root folder add a file called nuget.config and add the below lines to that files for restore,
  1. <?xml version=”1.0" encoding=”utf-8"?>    
  2.    <configuration>    
  3.       <packageSources>    
  4.          <add key=”dotnet6" value=”https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />    
  5.          <add key=”xamarin” value=”https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json" />    
  6.       </packageSources>    
  7.    </configuration>     
Step 7
 
Now open a new terminal in VS code and run the command as shown to restore all dependencies for the project.Once done you can see the usings in VS code in green color.
  1. dotnet restore  
 
Step 8
 
After stpe6 now we can see all the packages errors are gone and we are ready to build our application. Type dotnet build at same terminal and the app will begin to build it might take some time for first time build. In the meanwhile connecting an emulator or physical android device(Mac users can test on iPhones).
  1. dotnet build   
 
 
Step 9
 
Now it's time to see some output on an android device with our brand new Maui application. To do that in the same terminal type command as shown below and once build is done we can see the app deployed to our android phone.
  1. dotnet build -t:Run -f net6.0-android  
 
Demo
 
 
Additional points
 
For iOS and Mac app to run,
  1. dotnet build -t:Run -f net6.0-ios  
  2. dotnet build -t:Run -f net6.0-maccatalyst  
Limitations
  1. Some of the options like Display Alert may not work as Maui is still in preview mode.
  2. No direct debugging support from VS code and provided via Visual studio preview versions.
  3. Some of the nugets may not be supported.

Conclusion

 
Maui looks to be great in initial impressions with fastest build times and hope Microsoft continues to improve mobile experience.