Welcome to the first of what I hope to be many blog posts on .NET MAUI. MAUI stands for Multi-platform App User Interface. It is a framework that allows a developer to write one run many (WORM). To be clear it is a framework that allows a .NET developer to write an application in one solution and target Windows, Mac, iOS, and Android. In practice it’s amazing and it does just that.
How do I get it?
There are a couple of ways to get started with .NET MAUI. The first and probably the easiest is to download the latest preview of Visual Studio 2022 v17.3 preview 1.1 . I know what you are thinking: why are you having me install preview bits? I thought that .NET MAUI was released. Well .NET MAUI is released but the tooling isn’t quite ready yet. Don’t worry, this version of Visual Studio is pretty stable. At least I haven’t had any issues with it. Also, you can install it side by side with your existing Visual Studio install. When you install make sure to check the .NET Multi-platform App UI development Workload found under the Desktop & Mobile heading in the Visual Studio Installer. This will install .NET MAUI.
Then when you create a new project you’ll see options for a .NET MAUI App, a .NET MAUI Blazor App, or a .NET MAUI Class Library.
The other way to get started with .NET MAUI is with just the command line interface. Once you install the latest version of .NET 6
you should be able to type
dotnet new --list and you’ll see a list of all the templates that .NET knows about. At the top should be 8 templates related to .NET MAUI. To start a project just type this on the command line
dotnet new maui -o my-great-project and .NET will create a new project for you that you can then edit in VSCode or your favorite code editor.
I’ll cover Mac dev in a separate blog post. I couldn’t get it working when I tried, but I think that’s because I have too many legacy Xamarin bits laying around.
I’ve got it. Now what?
So now you know what it is, and you have it installed. Let’s get started with the “Hello, world!” app. I’m going to focus on Visual Studio for the rest of this series. Just know that this can all be done on the command line and using any text editor. I find Visual Studio’s tooling a little more intuitive than the command line. The community version of Visual Studio is free for learners and open source devs so there’s really no reason to not use it.
So open Visual Studio and select the option for Create a new project. In the Create a new project dialog that appears (seen below) select the All project types drop down and select MAUI. You’ll see the tree options I mentioned before. We’ll select the first one for .NET MAUI App and click Next.
This is cliche at this point, but we’re going to write a simple to-do application in these posts. So in the Project name field enter
maui-to-do. Select an appropriate location for it and click the Create button at the bottom right.
Visual Studio will scaffold up a new .NET MAUI application and place you in the MainPage.xaml file. Let’s press the big green play button in the tool bar right next to Windows Machine. This will start the application and run it on Windows.
You can click the Click me button and the text will change to show how many times you clicked the button. You can change the code and Hot Reload will kick in and change the code on the fly. You can set break points and the debugger will stop when you hit them. Basically everything you’ve come to expect from a development environment.
I’m going to end this post here. Keep checking back for more posts in this series (there’s an RSS feed if you want to subscribe). Thank you for reading. If you find this interesting let me know @spatacoli on Twitter. If you’d like to see this presented as a video on YouTube let me know and I’ll record it.