This repository is to host the .NET MAUI Project Templates, Item Templates and Code Snippets.
We all know that .NET MAUI is an evolution of Xamarin.Forms.
And now, Production supported .NET MAUI RC2 released on 27 Apr 2022 along with VS2022 Version 17.2.0 Preview 5.0, inching closer to GA.
Templates have been updated to support the latest release and is available to install from.
Join me on Developer Thoughts, an exclusive blog for .NET MAUI and Blazor, for articles on working with these templates and much more.
NuGet | VS Marketplace |
---|---|
To provide an integrated experience, a VS extension has been developed to host these templates.
Extension is made available in the Visual Studio Marketplace and even more easier, can be installed from within Visual Studio itself (Extensions -> Manage Extensions / Alt + X + M).
This has Project Templates for:
- .NET MAUI App (RC2) - An All-in-One .NET MAUI App Project Template - For more details, check out this article
- .NET MAUI App (C#) (RC2)
- .NET MAUI Class Library (RC2)
And has Item Templates for:
- Content Page (.NET MAUI)
- Content Page (C#) (.NET MAUI)
- Content View (.NET MAUI)
- Content View (C#) (.NET MAUI)
- Resource Dictionary (.NET MAUI)
- Resource Dictionary (XAML only)(.NET MAUI)
- Shell Page (.NET MAUI)
Now VS2022 extension is loaded with 25+ C# and XAML Code Snippets.
XAML Snippets for new Layouts, Gestures, Color, Style.
C# Snippets for Properties such as Attached, Bindable, ViewModel and Comet (MVU design pattern).
Types such as record
and record struct
.
Snippets for Method definition, Event Handler definition (async version also).
For making use of these templates cross-platform, have provided it as .NET CLI template package distributed via NuGet.
Install the template package from NuGet with the below command.
dotnet new --install VijayAnand.MauiTemplates
If you've already installed this package, then this can be updated to the latest version with the below command.
dotnet new --update-check
dotnet new --update-apply
This comes with with the following templates:
Name | Template Name | Type |
---|---|---|
.NET MAUI App | mauiapp | Project |
.NET MAUI Class Library | mauiclasslib | Project |
ContentPage | maui-page | Item |
ContentPage (C#) | maui-page-cs | Item |
ContentView | maui-view | Item |
ContentView (C#) | maui-view-cs | Item |
ResourceDictionary | maui-resdict | Item |
ShellPage | maui-shell | Item |
In .NET CLI, all of these templates takes two parameters:
-
Name: (Short notation:
-n
)The name of the project/page/view to create. For pages/views, don't need to suffix it with .xaml, it will get added.
If the name parameter is not specified, by default, the .NET CLI template engine will take the current folder name as the filename (current behaviour of the templating engine).
-
Namespace: (Short notation:
-na
)The namespace for the generated files.
-
Now with more options while creating the app or class library project, ability to include NuGet packages on the fly for
CommunityToolkit.Maui
,CommunityToolkit.Maui.Markup
,CommunityToolkit.Mvvm
or all.
Note: Parameter values are case-insensitive.
Both project templates take the below optional parameters to include the officially supported CommunityToolkit NuGet packages:
-it
|--include-toolkit
- Accepted Values areYes
orNo
(default isNo
)-im
|--include-markup
- Accepted Values areYes
orNo
(default isNo
)-imt
|--include-mvvm-toolkit
- Accepted Values areYes
orNo
(default isNo
)
All-in-One .NET MAUI App project takes one additional parameter to define the application design pattern:
-dp
|--design-pattern
Can take any one of the following values, with default value set to Plain
:
Parameter Value | Description |
---|---|
Plain | App configured to work with a single, initial screen. |
Hierarchical | App configured to work in a hierarchical pattern using NavigationPage. |
Tab | App configured to work in a Tabbed fashion using TabbedPage. |
Shell | App configured to work with Routes using Shell page. |
Hybrid | App configured to work in a Hybrid fashion using BlazorWebView. |
For more details: run this command in the terminal (use -h
to save some keystrokes):
dotnet new mauiapp --help
dotnet new mauiclasslib --help
After installation, use the below command(s) to create new artifacts using the template (both provide the same output):
With parameter names abbreviated:
.NET MAUI App:
dotnet new mauiapp -n MyApp -dp Hybrid
Option to include NuGet packages:
dotnet new mauiapp -n MyApp -dp Shell -it yes -im yes -imt yes
.NET MAUI Class Library:
dotnet new mauiclasslib -n MyApp.Core
Option to include NuGet packages:
dotnet new mauiclasslib -n MyApp.Core -it yes -im yes -imt yes
Pages:
dotnet new maui-page -n LoginPage -na MyApp.Views
dotnet new maui-page-cs -n HomePage -na MyApp.Views
Views:
dotnet new maui-view -n CardView -na MyApp.Views
dotnet new maui-view-cs -n OrderView -na MyApp.Views
Shell:
dotnet new maui-shell -n AppShell -na MyApp
With parameter names expanded:
.NET MAUI App:
dotnet new mauiapp --name MyApp --design-pattern Hybrid
Option to include NuGet packages:
dotnet new mauiapp --name MyApp --design-pattern Shell --include-toolkit yes --include-markup yes --include-mvvm-toolkit yes
.NET MAUI Class Library:
dotnet new mauiclasslib --name MyApp.Core
dotnet new mauiclasslib --name MyApp.Core --include-toolkit yes --include-markup yes --include-mvvm-toolkit yes
Pages:
dotnet new maui-page --name LoginPage --namespace MyApp.Views
dotnet new maui-page-cs --name HomePage --namespace MyApp.Views
Views:
dotnet new maui-view --name CardView --namespace MyApp.Views
dotnet new maui-view-cs --name OrderView --namespace MyApp.Views
Shell:
dotnet new maui-shell --name AppShell --namespace MyApp