Xamarin : Step-by-Step Guide To Building .NET Multi-platform App (MAUI) using Visual Studio 2019 Preview 16.10
Xamarin was released 10 years before, it has helped many developers to develop mobile apps with multi-platform with native feel but now it’s time to say goodbye to Xamarin and happily welcome .NET MAUI (Multi-platform App UI).
Let’s go back a bit in time first, the name Xamarin comes from the name of the Tamarin monkey, replacing the leading T with an X.
On May 16, 2011, Miguel de Icaza announced on his blog that Mono would be developed and supported by Xamarin.
In 2016, Xamarin has been acquired by Microsoft, after that Xamarin is open source and removed payment options. This helped the adoption of Xamarin. Microsoft then integrated Xamarin into Visual Studio. All the mobile development company started using visual studio in both Windows and Mac, it is great improvement after Microsoft acquires Xamarin.
Every developer and company should be very clear, Microsoft isn’t throwing away Xamarin. Mono won’t be going anywhere yet. .NET MAUI is the next generation of Xamarin Forms, intended to allow developers to build an app once in a single Visual Studio project with a single codebase, targeting any supported device. The aim is to deliver a simplified project structure. Rather than a single solution with separate projects for each platform you’re targeting, with MAUI a single project will contain the resources needed to target specific platforms.
David blog helped me to understand more about setup. In this article, I will explain how to create the first hello world app using the MAUI application.
Visual Studio 2019 Preview
Visual studio 2019 early access preview version you can download from Microsoft website . This release is not "go-live" so not recommended to use on production computers or for creating production code.Verify MAUI SDK Installation
Previously was install all the required SDK is manual, Now, Jonathan Dick has put together a useful dotnet tool that evaluates your system and gathers as many of the required pieces as it can. To get started, install maui-check globally from the command line.Open Run CMD as an Administrator mode and install MAUI Check tool using the below line
dotnet tool install -g Redth.Net.Maui.Check
After MAUI check tool install, will start to execute the below the line of code to verify the SDK installation
maui-check
You need to install the Preview 2 version of the dotNet 6 SDK, as well as the Preview 2 Android, iOS, and Mac Catalyst workloads so if you are getting any error alert saying SDK is missing, keep give input as “Yes” for install the missing SDK and wait for the “Congratulations, everything looks great!” message, that means, you are ready to start the new MAUI application.
Create a new MAUI Mobile application
Visual Studio 2019 Preview version default available MAUI project template and select Create a new project, otherwise, you can download the default project sample available in the Git MAUI official repository.Search for "MAUI" or choose Mobile from the Project type menu. Select the .Net Maui Mobile application
Choose a project name – the example uses "HelloMaui" and click on Create
Once you click on create button automatically solutions will generate. Before building the solutions, Let quickly understand all the folders and files.
MAUI Application Startup
Multi-targeted .NET MAUI Single Project for iOS and Android. .NET MAUI starts every application using Microsoft.Extensions HostBuilder.Each platform has a different starting point, and the consistent point of entry for your application is Startup.cs will allow the following. It includes a Configure method to pipe service registration, handler registration
public class Startup : IStartup
{
public void Configure(IAppHostBuilder appBuilder)
{
appBuilder .UseMauiApp<App>();
}
}
Application customization processes, this is where you can do such things as register fonts and register compatibility for Xamarin.Forms renderers or your own custom renderers, By default, if you don't want to customize anything special, ignore this
appBuilder
.UseFormsCompatibility()
.UseMauiApp<App>()
.ConfigureFonts(fonts => {
fonts.AddFont("ionicons.ttf", "IonIcons");
})
MAUI Application Life cycle
.Net MAUI Application preview 3 Support to manage the life cycle of the application. Life Cycle API included in Startup.cs file and will write platform-specific.public void Configure(IAppHostBuilder appBuilder)
{
appBuilder
.ConfigureLifecycleEvents(lifecycle => {
#if ANDROID
lifecycle.AddAndroid(d => {
d.OnBackPressed(activity => {
System.Diagnostics.Debug.WriteLine("Back button pressed!");
});
});
#endif
});
}
MAUI App.Xaml
In App.Xaml.cs project inherited by Microsoft.Maui.Controls.Application and make sure MAUI namespace added specify common Image directory for all the platformusing Microsoft.Maui;
using Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific;
namespace HelloMaui
{
public partial class App : Microsoft.Maui.Controls.Application
{
public App()
{
InitializeComponent();
}
public override IWindow CreateWindow(IActivationState activationState)
{
Microsoft.Maui.Controls.Compatibility.Forms.Init(activationState);
this.On<Microsoft.Maui.Controls.PlatformConfiguration.Windows>()
.SetImageDirectory("Assets");
return new MainWindow();
}
}
}
In App.Xaml, will work same like xamairn form and will add all the common resources and style
<Application xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:HelloMaui"
x:Class="HelloMaui.App">
<Application.Resources>
<ResourceDictionary>
<!-- Add any additional resources here. -->
<Color x:Key="PageBackgroundColor">White</Color>
<Color x:Key="PrimaryTextColor">Black</Color>
<Color x:Key="GlyphColor">#2B0B98</Color>
<Style TargetType="Label">
<Setter Property="TextColor" Value="{DynamicResource PrimaryTextColor}" />
</Style>
<Style TargetType="Label" x:Key="Glyph">
<Setter Property="TextColor" Value="{DynamicResource GlyphColor}" />
<Setter Property="FontFamily" Value="IonIcons" />
<Setter Property="FontSize" Value="32" />
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
Application icon
The application icon is one great improvement, the AppIcon folder will available under the MAUI project and it is just a single SVG, Looks like Maui will just automatically take care of generating all the different icon sizes for different devices.MAUI Design Screen
AssemblyInfo.cs file is removed from solutions. Main Page Name not changed. The xaml looks like below and you can observe below code the concept of SemanticProperties is added<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="HelloMaui.MainPage"
BackgroundColor="{DynamicResource PageBackgroundColor}">
<ScrollView>
<StackLayout Padding="{OnPlatform iOS='30,60,30,30', Default='30'}">
<Label Text="Getting started with MAUI Xamarin Forms Application using Visual Studio 2019 Preview 16.10"
SemanticProperties.HeadingLevel="Level1"
FontSize="32"
HorizontalOptions="CenterAndExpand" />
<Label Text="Welcome to .NET MAUI!"
HorizontalOptions="CenterAndExpand" />
<Image
Source="dotnet_bot.png"
SemanticProperties.Description="Cute dotnet bot waving hi to you!"
Margin="40,0" />
</StackLayout>
</ScrollView>
</ContentPage>
In MainPage.xaml.cs removed using Xamarin.Forms, add an inheritance from IPage, added the Maui namespace
using System;
using Microsoft.Maui;
using Microsoft.Maui.Controls;
using Microsoft.Maui.Controls.Xaml;
namespace HelloMaui
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class MainPage : ContentPage, IPage
{
public MainPage()
{
InitializeComponent();
}
public IView View { get => (IView)Content; set => Content = (View)value; }
}
}
Restore MAUI Nuget package
Before you will build and run solutions make sure NuGet packages referenced in the configuration file.Right Click on Solutions > Open Folder in File Explorer
Make sure global.json and NuGet.config file available before building the solutions
MAUI global.json
global.json file look like below{
"sdk": {
"version": "6.0.100-preview.3.21202.5",
"rollForward": "disable",
"allowPrerelease": true
}
}
MAUI Nuget.Config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<packageSources>
<clear />
<!-- ensure only the sources defined below are used -->
<add key="dotnet6" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet6/nuget/v3/index.json" />
<add key="xamarin" value="https://pkgs.dev.azure.com/azure-public/vside/_packaging/xamarin-impl/nuget/v3/index.json" />
<add key="public" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-public/nuget/v3/index.json" />
</packageSources>
<config>
<add key="globalPackagesFolder" value="packages" />
</config>
</configuration>
Build and Run MAUI Android App
Inside Android Folder, not find any MainActivity.cs, only available Resource folder and Androidmanifest file. You will need the Android SDK installed as well as Android SDK Platform 30. When you did a verified MAUI check, SDK was download and installed, if no, a simple way to get this is to install the current Xamarin workload and go to Tools > Android > Android SDK Manager from within Visual Studio.Try to click on Run Icon, if you are getting any issue, Right-click on the solution and Select in the open terminal
Build the MAUI Project, run the below comment in the Visual studio terminal
dotnet build HelloMauiYou can launch the Android project to an attached emulator or device
dotnet build HelloMaui -t:Run -f net6.0-android
Once the build is successful, the Android emulator / on-device application will run like below
Build and Run iOS Project in window machine
The build and debug .NET 6 iOS applications from Visual Studio 2019 preview. iOS folder is very clean, you can find Appdelegate.cs, Entitlements.plist, info.plist, Launchscreen.storyboard and Program.CS(Main.cs gets renamed Program.cs)If while connecting Visual Studio to your Mac through XMA you are prompted to install a different version of the SDK, you can ignore that since it refers to the legacy one. Make sure Xcode 12.4 installed in mac machine,
You can launch the iOS project to an attached iOS Simulator. Initially not working for me run the ios app in windows after that start working.
dotnet build HelloMaui -t:Run -f net6.0-iosOnce the build is successful, the iOS simulator/ Device will show the output like below
Good Article!!!
ReplyDeleteThanks DhanaShekar
DeleteHi
DeleteI have created a MAUI project in VS 2022 preview, which is working fine initially with emulator, but now Emulator is not showing. When I create Xamarin project Emulator is showing and application is running on that Emulator.
Please help me to resolve this issue as it occurs developing application
What I have tried:
1. I had delete/renamed
Copy Code
C:\Users\username\AppData\Local\Xamarin
C:\Users\username\AppData\Local\Microsoft\VisualStudio\17.0_e17a11fb\ComponentModelCache
2. I had repair VS 2022 preview
3. I had reinstall MAUI
Hi Mohammad,
DeleteCan you try this demo video steps with latest VS 2022
https://www.youtube.com/watch?v=7mQyGL0wIsk&t=4s
This is a very good article but the author obviously struggles with English. A ten minute edit would hugely improve understanding.
ReplyDeleteThanks John for your valuable feedback
DeleteHow does this compare with Uno platform.
ReplyDeleteHello, UNO has strong support for WPF and UWP and support WIndows7 , Tizen, and Linux (GTK), I am not much used UNO. Uno team has also covered this question in the docs - https://platform.uno/docs/articles/intro.html#how-is-uno-platform-different-from-net-maui
DeleteI am try install .NET MAUI with step by step guide line .but when open visual studio 2019 not showing .net MAUI application
ReplyDeleteHello RaviKumar, MAUI still, it's not yet released officially,Visual studio 2019 early access preview version you can download from the Microsoft website - https://visualstudio.microsoft.com/vs/preview/
DeleteThanks OVI
ReplyDeletebuying ytviews See why it is important for an online marketer to record a YouTube video. In order to become popular and taken seriously as an online marketer, one must be committed to making many recordings and uploading them to YouTube. Remember if YouTube is the third most visited site on the internet, than your name could become well known and your marketing possibilities would be endless.
ReplyDeleteSometimes, and through no fault of yours, things can go topsy-turvy on you. For richer or poorer.networthmart.com
ReplyDeleteThe writer has outdone himself this time. It is not at all enough; the website is also utmost perfect. I will never forget to visit your site again and again. https://fmovies.group
ReplyDeleteI am thankful to you for sharing this plethora of useful information. I found this resource utmost beneficial for me. Thanks a lot for hard work. https://soap2day.digital
ReplyDeleteThis was a really great contest and hopefully I can attend the next one. It was alot of fun and I really enjoyed myself.. https://megashare-website.com
ReplyDeleteFriend, this web site might be fabolous, i just like it. https://soap2dayy.co
ReplyDeleteGoing to graduate school was a positive decision for me. I enjoyed the coursework, the presentations, the fellow students, and the professors. And since my company reimbursed 100% of the tuition, the only cost that I had to pay on my own was for books and supplies. Otherwise, I received a free master’s degree. All that I had to invest was my time. Window replacement
ReplyDeleteI high appreciate this post. It’s hard to find the good from the bad sometimes, but I think you’ve nailed it! would you mind updating your blog with more information? https://gogostream.co
ReplyDeleteYou delivered such an impressive piece to read, giving every subject enlightenment for us to gain information. Thanks for sharing such information with us due to which my several concepts have been cleared. https://movie4k.media
ReplyDeleteVery useful post. This is my first time i visit here. I found so many interesting stuff in your blog especially its discussion. Really its great article. Keep it up. https://primewire-movies.com
ReplyDeleteThis is such a great resource that you are providing and you give it away for free. I love seeing blog that understand the value of providing a quality resource for free https://xmovies8.one
ReplyDeleteOutstanding article! I want people to know just how good this information is in your article. Your views are much like my own concerning this subject. I will visit daily your blog because I know. It may be very beneficial for me. https://putlocker.quest
ReplyDeletePretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. https://onlinemovie25.com
ReplyDeleteSome critics dislike this movie because they know what Mr. Smith is trying to accomplish with this type of movie, and they don't like it. While Smith's traditional audience may be slow to co-sign this movie افلام اجنبي مباشرة
ReplyDeleteI can’t believe focusing long enough to research; much less write this kind of article. You’ve outdone yourself with this material without a doubt. It is one of the greatest contents. https://putlocker.work
ReplyDeletePositive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. https://projectfreetv.space/
ReplyDeleteExcellent and very exciting site. Love to watch. Keep Rocking. https://y-ymovies.com
ReplyDeleteI am always looking for some free kinds of stuff over the internet. There are also some companies which give free samples. But after visiting your blog, I do not visit too many blogs. Thanks. https://vumoo.vip
ReplyDeleteThis is a great inspiring article.I am pretty much pleased with your good work.You put really very helpful information. Keep it up. Keep blogging. Looking to reading your next post. https://solar-movies.one
ReplyDeleteExcellent blog! I found it while surfing around on Google. Content of this page is unique as well as well researched. Appreciate it. https://afdah.space
ReplyDeleteKeep up the good work; I read few posts on this website, including I consider that your blog is fascinating and has sets of the fantastic piece of information. Thanks for your valuable efforts. https://aafdah.org
ReplyDeleteThank you so much as you have been willing to share information with us. We will forever admire all you have done here because you have made my work as easy as https://couchtunerweb.site
ReplyDeleteI am incapable of reading articles online very often, but I’m happy I did today. It is very well written, and your points are well-expressed. I request you warmly, please, don’t ever stop writing. https://123moviesite.one
ReplyDeleteI have a hard time describing my thoughts on content, but I really felt I should here. Your article is really great. I like the way you wrote this information https://couchtuner.quest
ReplyDeleteThanks for an interesting blog. What else may I get that sort of info written in such a perfect approach? I have an undertaking that I am just now operating on, and I have been on the lookout for such info. https://123moviesnow.space
ReplyDeleteI read a article under the same title some time ago, but this articles quality is much, much better. How you do this.. https://putlocker-movies.space
ReplyDeleteWithout fail, your writing style is top professional; even your website also looks amazing thank you for posting. https://la-123movies.one
ReplyDeleteVery interesting blog. Alot of blogs I see these days don't really provide anything that I'm interested in, but I'm most definately interested in this one. Just thought that I would post and let you know. https://123putlocker.website
ReplyDeleteI found that site very usefull and this survey is very cirious, I ' ve never seen a blog that demand a survey for this actions, very curious https://soap2day.shop
ReplyDeleteRemarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive https://soap2day.monster
ReplyDeleteI really like your writing style, great information, thankyou for posting. https://putlockertv.one
ReplyDeletePretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. https://solarmovies.space
ReplyDeleteRemarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive https://soaptoday.space
ReplyDeleteFabulous post, you have denoted out some fantastic points, I likewise think this s a very wonderful website. I will visit again for more quality contents and also, recommend this site to all. Thanks. https://movies123.win
ReplyDeleteRemarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive! https://newputlocker.website
ReplyDeleteThis article was written by a real thinking writer without a doubt. I agree many of the with the solid points made by the writer. I’ll be back day in and day for further new updates. https://thesolarmovies.space
ReplyDeleteRemarkable article, it is particularly useful! I quietly began in this, and I'm becoming more acquainted with it better! Delights, keep doing more and extra impressive https://watchcouchtuner.space
ReplyDeleteI am thankful to you for sharing this plethora of useful information. I found this resource utmost beneficial for me. Thanks a lot for hard work. https://1primewire.site
ReplyDeletethank you for your interesting infomation. indian visa application
ReplyDeleteI love the way you write and share your niche! Very interesting and different! Keep it coming! AMERIKAS VĪZAS PIETEIKUMS TIEŠSAISTĒ
ReplyDeletei love reading this article so beautiful!!great job! UNITED STATES VISA FOR SPANISH CITIZENS
ReplyDeleteIm no expert, but I believe you just made an excellent point. You certainly fully understand what youre speaking about, and I can truly get behind that. INDIA VISA FROM AUSTRALIA
ReplyDeleteI am very much pleased with the contents you have mentioned. I wanted to thank you for this great article. Canada Visa Application
ReplyDeletePretty good post. I just stumbled upon your blog and wanted to say that I have really enjoyed reading your blog posts. Any way I'll be subscribing to your feed and I hope you post again soon. Big thanks for the useful info. Turkey Visa Online Application
ReplyDeleteAwesome dispatch! I am indeed getting apt to over this info, is truly neighborly my buddy. Likewise fantastic blog here among many of the costly info you acquire. Reserve up the beneficial process you are doing here. Kanada Visa -oanfraach
ReplyDeleteThis is very significant, and yet necessary towards just click this unique backlink: UNITED STATES VISA FOR FRENCH CITIZENS
ReplyDeleteThank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info. INDIEN VISA ONLINE
ReplyDeleteA very awesome blog post. We are really grateful for your blog post. You will find a lot of approaches after visiting your post. indian visa eligible countries
ReplyDeleteHello, this weekend is good for me, since this time i am reading this enormous informative article here at my home. cara daftar situs judi qiu qiu online 10000
ReplyDeleteThanks, that was a really cool read! 토토커뮤니티
ReplyDeleteThese things are very important, good think so - I think so too... 꽁머니사이트
ReplyDeleteOn that website page, you'll see your description, why not read through this. VISA INDIA YANG SANGAT
ReplyDeleteOnly aspire to mention ones content can be as incredible. This clarity with your post is superb and that i may think you’re a guru for this issue. High-quality along with your concur permit me to to seize your current give to keep modified by using approaching blog post. Thanks a lot hundreds of along with you should go on the pleasurable get the job done. IfB Verlag Deutsche Sprache
ReplyDeleteAcknowledges for penmanship such a worthy column, I stumbled beside your blog besides predict a handful advise. I want your tone of manuscript... 먹튀검증사이트
ReplyDeleteThank you for some other informative website. The place else may just I get that kind of information written in such a perfect method? I have a venture that I am simply now running on, and I’ve been at the glance out for such info. wild hemp hempettes
ReplyDeletePositive site, where did u come up with the information on this posting?I have read a few of the articles on your website now, and I really like your style. Thanks a million and please keep up the effective work. Commercial Roofers
ReplyDeleteI have read all the comments and suggestions posted by the visitors for this article are very fine,We will wait for your next article so only.Thanks! Domanda di visto online per il Canada
ReplyDeleteIf more people that write articles really concerned themselves with writing great content like you, more readers would be interested in their writings. Thank you for caring about your content. สุดยอดเกมไพ่
ReplyDeleteThis is very significant, and yet necessary towards just click this unique backlink: 먹튀검증사이트
ReplyDeleteYou should mainly be superior together with well-performing material, which means that see it: beylikduzu eskort
ReplyDeleteIt is very good, but look at the information at this address. 스포츠중계
ReplyDeleteI invite you to the page where see how much we have in common. pggame
ReplyDeleteThis is very interesting, but it is necessary to click on this link: pggame
ReplyDeleteWhen you use a genuine service, you will be able to provide instructions, share materials and choose the formatting style. Requisitos de la Visa de Turquía
ReplyDeleteThank you for taking the time to publish this information very useful! INDIA MEDICAL VISA
ReplyDeletePositive site, where did u come up with the information on this posting? I'm pleased I discovered it though, ill be checking back soon to find out what additional posts you include. 꽁머니
ReplyDeleteHey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. Requisitos de la Visa de Turquía
ReplyDeleteExcellent and very exciting site. Love to watch. Keep Rocking. http://oisjrgiks.com
ReplyDeleteIt is a great website.. The Design looks very good.. Keep working like that!. 먹튀검증
ReplyDeleteThis is very educational content and written well for a change. It's nice to see that some people still understand how to write a quality post! USA Visa
ReplyDeleteGreat article Lot's of information to Read...Great Man Keep Posting and update to People..Thanks VIZA ZA INDIJO
ReplyDeleteInteresting topic for a blog. I have been searching the Internet for fun and came upon your website. Fabulous post. Thanks a ton for sharing your knowledge! It is great to see that some people still put in an effort into managing their websites. I'll be sure to check back again real soon. rims for sale
ReplyDeleteI would like to say that this blog really convinced me to do it! Thanks, very good post. 먹튀검증
ReplyDeleteGood website! I truly love how it is easy on my eyes it is. I am wondering how I might be notified whenever a new post has been made. I have subscribed to your RSS which may do the trick? Have a great day! voyance immediate par telephone
ReplyDeleteVery interesting information, worth recommending. However, I recommend this: Deutscher Hosting
ReplyDelete