VijayAnand.MauiTemplates 2.3.1

The ID prefix of this package has been reserved for one of the owners of this package by NuGet.org. Prefix Reserved
This package has a SemVer 2.0.0 package version: 2.3.1+sha.928dee7.
There is a newer version of this package available.
See the version list below for details.
dotnet new install VijayAnand.MauiTemplates::2.3.1
This package contains a .NET Template Package you can call from the shell/command line.

Project and Item Templates for developing .NET MAUI App that runs on iOS, Android, macOS, and Windows

  • All-in-One project template for .NET MAUI App and is named as mauiapp
  • .NET MAUI Class Library project template and is named as mauiclasslib
  • Shared Class Library (Xamarin.Forms and .NET MAUI) project template and is named as sharedclasslib

Item templates for the following:

Item Template Name
ContentPage (XAML) maui-page
ContentPage (C#) maui-page-cs
ContentView (XAML) maui-view
ContentView (C#) maui-view-cs
ResourceDictionary (XAML) maui-resdict
Shell (XAML) maui-shell

All of these templates currently target .NET MAUI on .NET 7 GA, stable release as of Nov 2022.

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-only
dotnet new update
Parameters:

Starting with v2.0.0 of the template package, to effectively support .NET MAUI on both .NET 6 and .NET 7, CLI project templates defines a new parameter named framework:

  • Framework: (Short notation: -f)

    This can take either net6.0 or net7.0 as its options (with net7.0 being the default value, if not provided).

    Examples:

    dotnet new mauiapp --framework net6.0
    

    Below command can be simplified to dotnet new mauiapp as default value of framework parameter is net7.0

    dotnet new mauiapp -f net7.0
    

In .NET CLI, all of these Item 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.

    While working with .NET 7 SDK, the namespace parameter in short notation needs to be passed as -p:na (i.e., it needs to be prefixed with -p:).

  • 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 .NET MAUI App and Class Library templates take the below optional Boolean parameters to include the officially supported CommunityToolkit NuGet packages:

Specifying the parameter name, either in short or full notation, implies that it is defined.

  • -it | --include-toolkit - Default is false
  • -im | --include-markup - Default is false
  • -imt | --include-mvvm-toolkit - Default is false
  • -cc | --conditional-compilation - Default is false

Additional parameters for App project:

The target for the Windows platform can be either Package (MSIX) or Unpackaged. By default, it is set as Package, this can be overridden while creating the project by including the below parameter:

  • -wu | --windows-unpackaged - Default is false

While targeting .NET 7, an option to add and configure Microsoft.Maui.Controls.Foldable, Microsoft.Maui.Controls.Maps, or both NuGet packages.

  • -if | --include-foldable - Default is false
  • -inm | --include-maps - Default is false

Note: If the project target .NET 6, selecting the Foldable/Maps option will NOT have any impact.

Conditional Compilation

And now conditional compilation can be configured so that platform source files can be defined anywhere in the project provided they follow a naming convention as mentioned below. This will allow maintaining related source files in the same place, especially MAUI Handlers.

  • *.Standard.cs - Files targeting the BCL
  • *.Android.cs - Files specific to Android
  • *.iOS.cs - Files shared with both iOS and MacCatalyst
  • *.MacCatalyst.cs - Files specific to MacCatalyst
  • *.Tizen.cs - Files specific to Tizen
  • *.Windows.cs - Files specific to Windows

For existing projects, add the below block of code in the project file (.csproj). This will modify the behavior of build process so due care must be taken if doing so.

<ItemGroup Condition="'$(TargetFramework)' != 'net6.0'">
    <Compile Remove="**\*.Standard.cs" />
    <None Include="**\*.Standard.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'ios' AND $([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'maccatalyst'">
    <Compile Remove="**\*.iOS.cs" />
    <None Include="**\*.iOS.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    <Compile Remove="**\iOS\**\*.cs" />
    <None Include="**\iOS\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'android'">
    <Compile Remove="**\*.Android.cs" />
    <None Include="**\*.Android.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    <Compile Remove="**\Android\**\*.cs" />
    <None Include="**\Android\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'maccatalyst'">
    <Compile Remove="**\*.MacCatalyst.cs" />
    <None Include="**\*.MacCatalyst.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    <Compile Remove="**\MacCatalyst\**\*.cs" />
    <None Include="**\MacCatalyst\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'tizen'">
    <Compile Remove="**\*.Tizen.cs" />
    <None Include="**\*.Tizen.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    <Compile Remove="**\Tizen\**\*.cs" />
    <None Include="**\Tizen\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

<ItemGroup Condition="$([MSBuild]::GetTargetPlatformIdentifier('$(TargetFramework)')) != 'windows'">
    <Compile Remove="**\*.Windows.cs" />
    <None Include="**\*.Windows.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
    <Compile Remove="**\Windows\**\*.cs" />
    <None Include="**\Windows\**\*.cs" Exclude="$(DefaultItemExcludes);$(DefaultExcludesInProjectFolder)" />
</ItemGroup>

All-in-One .NET MAUI App project takes two additional parameters to define the application design pattern and target platform respectively:

  • -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.
  • -tp | --target-platform

Can take any one of the following values, with default value set to All:

Parameter Value Description
All Targets all possible .NET MAUI supported platforms.
Android Targets Android platform.
iOS Targets iOS platform.
macOS Targets macOS platform via Mac Catalyst.
Windows Targets Windows platform.
Tizen Targets Tizen platform.
Mobile Targets Android and iOS platforms.
Desktop Targets Windows and macOS platforms.
Apple Targets iOS and macOS platforms.

Examples:

dotnet new mauiapp --design-pattern Hybrid --target-platform Mobile
dotnet new mauiapp -dp Shell -tp Android

Shared Class Library template take the below optional Boolean parameters to include the officially supported NuGet packages:

Specifying the parameter name, either in short or full notation, implies that it is defined.

Single parameter to include all the supported NuGet packages:

  • -asp | --all-supported-packages - Default is false

Specific to Xamarin.Forms:

  • -ife | --include-forms-essentials - Default is false
  • -ift | --include-forms-toolkit - Default is false
  • -ifm | --include-forms-markup - Default is false

Specific to .NET MAUI:

  • -imt | --include-maui-toolkit - Default is false
  • -imm | --include-maui-markup - Default is false

Common to both:

  • -inmt | --include-mvvm-toolkit - Default is false

For more details: run this command in the terminal (use -h to save some keystrokes):

dotnet new mauiapp --help
dotnet new mauiclasslib --help
dotnet new sharedclasslib --help
Usage:

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 -im -imt -inm -if

Option to configure conditional compilation:

dotnet new mauiapp -n MyApp -dp Shell -cc

.NET MAUI Class Library:

dotnet new mauiclasslib -n MyApp.Core

Option to include NuGet packages:

dotnet new mauiclasslib -n MyApp.Core -it -im -imt

Option to configure conditional compilation:

dotnet new mauiclasslib -n MyApp.Core -cc

Shared Class Library:

dotnet new sharedclasslib -n MyApp.UI

Option to include all supported NuGet packages:

dotnet new sharedclasslib -n MyApp.UI -asp

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

Resource Dictionary:

dotnet new maui-resdict -n LightTheme -na MyApp.Themes

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 --include-markup --include-mvvm-toolkit --include-maps --include-foldable
dotnet new mauiapp -n MyApp --design-pattern Shell --conditional-compilation

.NET MAUI Class Library:

dotnet new mauiclasslib --name MyApp.Core
dotnet new mauiclasslib --name MyApp.Core --include-toolkit --include-markup --include-mvvm-toolkit
dotnet new mauiclasslib --name MyApp.Core --conditional-compilation

Shared Class Library:

dotnet new sharedclasslib --name MyApp.UI
dotnet new sharedclasslib --name MyApp.UI --all-supported-packages

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

Resource Dictionary:

dotnet new maui-resdict --name LightTheme --namespace MyApp.Themes
  • .NETStandard 2.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
5.2.1 73 4/17/2024
5.2.0 54 4/10/2024
5.1.0 372 3/12/2024
5.0.1 704 2/18/2024
5.0.0 162 2/14/2024
4.9.0 192 2/8/2024
4.8.1 582 1/18/2024
4.8.0 127 1/15/2024
4.7.0 345 1/4/2024
4.6.0 1,035 11/30/2023
4.5.0 211 11/24/2023
4.4.0 332 11/14/2023
4.4.0-preview.5 149 11/10/2023
4.4.0-preview.4 78 11/9/2023
4.4.0-preview.3 282 10/30/2023
4.4.0-preview.2 354 10/18/2023
4.4.0-preview.1 78 10/18/2023
4.3.0 261 10/13/2023
4.2.2 225 10/7/2023
4.2.1 156 10/4/2023
4.2.0 94 10/4/2023
4.1.1 114 9/26/2023
4.1.0 149 9/13/2023
4.0.1 148 8/27/2023
4.0.0 118 8/17/2023
3.6.0 123 8/10/2023
3.5.0 155 7/14/2023
3.4.1 167 6/14/2023
3.4.0 99 6/13/2023
3.3.2 147 5/18/2023
3.3.1 98 5/17/2023
3.3.0 102 5/16/2023
3.2.4 170 4/20/2023
3.2.3 120 4/17/2023
3.2.2 109 4/14/2023
3.2.1 109 4/11/2023
3.2.0 111 4/5/2023
3.2.0-preview.6 97 4/3/2023
3.2.0-preview.5 96 4/2/2023
3.2.0-preview.4 93 3/30/2023
3.2.0-preview.3 101 3/27/2023
3.2.0-preview.2 99 3/25/2023
3.2.0-preview.1 95 3/24/2023
3.1.0 156 3/23/2023
3.1.0-preview.9 93 3/20/2023
3.1.0-preview.8 98 3/18/2023
3.1.0-preview.7 99 3/15/2023
3.1.0-preview.6 94 3/14/2023
3.1.0-preview.5 96 3/11/2023
3.1.0-preview.4 92 3/9/2023
3.1.0-preview.3 99 3/7/2023
3.1.0-preview.2 96 3/4/2023
3.1.0-preview.1 97 3/3/2023
3.0.2 177 3/6/2023
3.0.1 120 3/3/2023
3.0.0 143 2/22/2023
2.4.1 126 2/17/2023
2.4.0 138 2/6/2023
2.3.1 161 1/27/2023
2.3.0 130 1/25/2023
2.2.0 165 12/19/2022
2.1.3 1,007 11/23/2022
2.1.2 332 11/18/2022
2.1.1 317 11/10/2022
2.1.0 306 11/8/2022
2.0.3 362 10/26/2022
2.0.2 363 10/25/2022
2.0.1 406 10/21/2022
2.0.0 433 10/4/2022
1.7.3 552 8/5/2022
1.7.2 582 6/17/2022
1.7.1 448 6/7/2022
1.7.0 495 5/24/2022
1.6.0 432 5/23/2022
1.5.0 486 5/12/2022
1.4.1 529 4/28/2022
1.4.0 416 4/27/2022
1.3.1 478 4/19/2022
1.3.0 473 4/14/2022
1.2.0 494 3/29/2022
1.1.3 555 2/19/2022
1.1.2 425 2/18/2022
1.1.1 448 2/16/2022
1.1.0 403 2/16/2022
1.0.8 429 2/14/2022
1.0.7 420 2/14/2022
1.0.6 452 2/1/2022
1.0.5 416 1/31/2022
1.0.4 369 11/9/2021
1.0.3 375 10/15/2021
1.0.2 982 8/16/2021
1.0.1 409 8/13/2021
1.0.0 342 8/12/2021

What's new in ver. 2.3.1:
-------------------------
CommunityToolkit.Maui.MediaElement NuGet package bumped to v1.0.1 with the explicit WindowsAppSDK reference removed.

v2.3.0:

1. Ability to add reference to CommunityToolkit.Maui.MediaElement NuGet package and configure it in startup pipeline for playing audio/video in a .NET MAUI app

2. Dependent packages have been updated to reference latest stable version

CommunityToolkit.Maui - v4.0.0
CommunityToolkit.Mvvm - v8.1.0

v2.2.0:

1. Template package updated to support .NET 7 SR1 (v7.0.52).

2. Base framework is also included as a target (net6.0/net7.0) to .NET MAUI App project template when the target-platform is set to All.

3. To create a XAML-only resource dictionary template, include either --xaml-only (-xo) or --no-code-behind (-ncb) parameter.

v2.1.3:

The target-platform parameter is now updated as a multi-choice value. Can be opted-in according to the need.

And little housekeeping to improve the reliability of the templates.

v2.1.1:

1. Template package updated to support newly released .NET 7 NuGet dependencies.

2. For App project targeting .NET 7, option to add and configure Maui Foldable NuGet package.

Note: If the project target .NET 6, selecting the Foldable/Maps option will NOT have any impact.

v2.1.0:

Template package updated to support .NET 7 GA release.

v2.0.3:

1. A parameter named target-platform has been introduced that takes any one of the following values (with All being the default value).

All - Targets all possible .NET MAUI supported platforms.
Android - Targets Android platform.
iOS - Targets iOS platform.
macOS - Targets macOS platform via Mac Catalyst.
Windows - Targets Windows platform.
Tizen - Targets Tizen platform.
Mobile - Targets Android and iOS platforms.
Desktop - Targets Windows and macOS platforms.
Apple - Targets iOS and macOS platforms.

dotnet new mauiapp --target-platform Mobile

dotnet new mauiapp -tp Android

v2.0.2:

Android targetSdkVersion set in accordance with the framework version selected.

.NET 7 - targetSdkVersion 33

.NET 6 - targetSdkVersion 31

v2.0.1:

Templates have been updated to support .NET MAUI on .NET 7 (RC2 - Preview release).

v2.0.0:

1. A parameter named framework has been introduced that takes either net6.0 or net7.0 as its options (with net7.0 being the default value).

dotnet new mauiapp --framework net6.0

dotnet new mauiapp -f net7.0

2. For App project targeting .NET 7, option to add and configure Maui Maps NuGet package.

Note: If project target .NET 6, selecting the Maps option will NOT have any impact.

Join me on Developer Thoughts (https://egvijayanand.in/), an exclusive blog for articles on .NET MAUI and Blazor.