VijayAnand.FormsTemplates
1.10.0
Prefix Reserved
dotnet new install VijayAnand.FormsTemplates::1.10.0
CLI Project and Item Templates for developing Xamarin.Forms App that runs on iOS, Android, and Windows
Join me on Developer Thoughts, an exclusive blog for Xamarin.Forms, .NET MAUI, and Blazor with articles on working with it.
Consult this Xamarin.Forms Templates article for further details.
Project template for Xamarin.Forms 5 Class Library and is named as formsclasslib
Class library project template take the below optional parameters to override its target framework and to include the officially released Xamarin.Forms.Maps
, Xamarin.CommunityToolkit
, Xamarin.CommunityToolkit.Markup
, Xamarin.Essentials
, CommunityToolkit.Mvvm
(aka Microsoft MVVM Toolkit), VijayAnand.Toolkit.Markup
(aka Shared Toolkit) or all NuGet packages:
-f
|--framework
- Default value isnetstandard2.0
-asp
|--all-supported-packages
- Default value isfalse
(See below)-it
|--include-toolkit
- Default value isfalse
-im
|--include-markup
- Default value isfalse
-ie
|--include-essentials
- Default value isfalse
-imt
|--include-mvvm-toolkit
- Default value isfalse
-ist
|--include-shared-toolkit
- Default value isfalse
Explicit option:
-inm
|--include-maps
- Default value isfalse
-iei
|--include-essentials-interfaces
- Default value isfalse
Note: The NuGet package version being added out-of-the-box are v5.x for the Xamarin packages, v2.x for the Xamarin Toolkit packages, v1.x for the Xamarin.Essentials package, and v8.x for the MVVM Toolkit package. The latest stable version.
Item | Template Name |
---|---|
Generic Item (XAML) | forms-item |
Generic Item (C#) | forms-item-cs |
ContentPage (XAML) | forms-page |
ContentPage (C#) | forms-page-cs |
ContentPage and ViewModel (XAML) | forms-mvvm |
ContentPage and ViewModel (C#) | forms-mvvm-cs |
ContentView (XAML) | forms-view |
ContentView (C#) | forms-view-cs |
ResourceDictionary (XAML) | forms-resdict |
ShellPage (XAML) | forms-shell |
ShellPage (C#) | forms-shell-cs |
To install the template NuGet package, use the below .NET CLI command:
dotnet new install VijayAnand.FormsTemplates
If you've already installed this package, then it can be updated to the latest version with the below command:
dotnet new update --check-only
dotnet new update
Use the below .NET CLI command to create the project, pages, and views out these templates:
dotnet new formsclasslib -o MyApp.Core
Library target framework override:
dotnet new formsclasslib -o MyApp.Core -f netstandard2.1
Option to include NuGet packages:
dotnet new formsclasslib -o MyApp.UI -it -im -ie -iei -imt -inm -ist
In a single parameter (Maps and Essentials Interfaces are exceptions, to be explicitly mentioned):
dotnet new formsclasslib -o MyApp.UI -asp -iei -inm
NuGet Central Package Management (CPM) feature:
This can be used in combination with other parameters too.
dotnet new formsclasslib -o MyApp.UI -cpm
Item Template options:
Here, -n
denotes the name of the Page/View that is to be created (for Pages/Shell/Views, don't need to suffix the type like HomePage
, OrderView
, AppShell
and file extension .xaml
/ .cs
, it will be added automatically) (Can also be specified as --name
in the expanded form).
Just mention only the name of the item that is to be created. Item Type and File Extension would be automatically added.
Note: If name parameter is not provided, the .NET CLI template engine will take the current folder name in the context as its name.
And -na
denotes the namespace under which the file is to be created (Can also be specified as --namespace
in the expanded form).
While working with .NET 7 or higher SDK, the namespace parameter in short notation needs to be passed as -p:na
(i.e., it needs to be prefixed with -p:
).
Generic Item:
Suffixes like Page, View, and so on are necessary while using generic item templates.
dotnet new forms-item -n ThemePopup -b xct:Popup -na MyApp.Views
Output: ThemePopup.xaml
and ThemePopup.xaml.cs
public partial class ThemePopup : Popup {}
dotnet new forms-item -n SearchPage -b FormsPage -g SearchViewModel -p:na MyApp.Views
Output: SearchPage.xaml
and SearchPage.xaml.cs
public partial class SearchPage : FormsPage<SearchViewModel> {}
MVVM:
dotnet new forms-mvvm -n Search -na MyApp.Views
dotnet new forms-mvvm-cs -n Settings -na MyApp.Views
Page:
dotnet new forms-page -n Login -na MyApp.Views
dotnet new forms-page-cs -n Home -na MyApp.Views
View:
dotnet new forms-view -n Card -na MyApp.Views
dotnet new forms-view-cs -n Order -na MyApp.Views
Shell:
dotnet new forms-shell -n App -na MyApp
dotnet new forms-shell-cs -n Mobile -na MyApp
Resource Dictionary:
With C# code-behind file:
dotnet new forms-resdict -n DefaultTheme -na MyApp.Themes
Without C# code-behind file - Xaml only (The option to be specified is -xo
or --xaml-only
):
dotnet new forms-resdict -n DarkTheme -na MyApp.Themes -xo
-
.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 |
---|---|---|
1.10.0 | 60 | 8/22/2024 |
1.9.0 | 58 | 6/24/2024 |
1.8.0 | 48 | 6/21/2024 |
1.7.0 | 1,624 | 1/16/2024 |
1.6.0 | 160 | 1/12/2024 |
1.5.0 | 1,247 | 11/25/2023 |
1.4.4 | 90 | 9/25/2023 |
1.4.3 | 119 | 3/16/2023 |
1.4.2 | 1,157 | 11/23/2022 |
1.4.1 | 397 | 11/4/2022 |
1.4.0 | 361 | 11/1/2022 |
1.3.1 | 551 | 5/31/2022 |
1.3.0 | 441 | 5/2/2022 |
1.2.0 | 480 | 4/20/2022 |
1.1.0 | 467 | 2/25/2022 |
1.0.0 | 451 | 2/3/2022 |
Join me on Developer Thoughts (https://egvijayanand.in/), an exclusive blog for articles on Xamarin.Forms, .NET MAUI and Blazor.
What's new in ver. 1.10.0:
--------------------------
1. Introduced an option to support the XML-based solution file (slnx) format.
This would be an explicit option since the SLNX feature is currently in the preview stage and is only supported on VS2022.
-slnx | --use-slnx - Default value is false
dotnet new formsclasslib -o FormsLib -slnx
2. Introduced the option to include a reference to the PolySharp NuGet package.
-ips | --include-polysharp - Default value is false
dotnet new formsclasslib -o FormsLib -ips
v1.9.0:
1. Introduced an option to reference Xamarin.Forms.Maps NuGet package.
2. While using the generic item template, support for adding Xamarin Community Toolkit namespace while defining base types with that particular xmlns scope (xct).
dotnet new forms-item -n ThemePopup -b xct:Popup -p:na MyApp.Views
v1.8.0:
Introduced using the NuGet CPM feature from within Visual Studio IDE.
v1.7.0
1. An innovative generic item template, in XAML and C#, for creating items of any type.
And it is named forms-item and forms-item-cs
Both need one required parameter, -b / --base, the base type.
Optionally takes another parameter, -g / --generic, to specify the generic base type.
In addition, the XAML template takes one more parameter, -xo / --xaml-only, when defined, generates only the XAML definition.
Note: Namespace resolution in both XAML and C# file is left to the user as deriving them with the template is outside its scope.
Example:
dotnet new forms-item -n ThemePopup -b xct:Popup -p:na MyApp.Views
Output: ThemePopup.xaml and ThemePopup.xaml.cs
public partial class ThemePopup : Popup {}
dotnet new forms-item -n SearchPage -b FormsPage -g SearchViewModel -p:na MyApp.Views
Output: SearchPage.xaml and SearchPage.xaml.cs
public partial class SearchPage : FormsPage<SearchViewModel> {}
2. Introduced an item template to generate Page and its ViewModel in a single command, available for both XAML and C#.
The Page will be generated in the Views folder and ViewModel will be generated in the ViewModels folder.
Can also be overridden to generate in the same folder with the -sf | --same-folder option.
The ViewModels are generated with the base class titled BaseViewModel (implementation left to the user).
Including CommunityToolkit.Mvvm, an officially supported NuGet package, would be the best fit as it makes it easy to work with the MVVM design pattern.
And it's recommended to use this MVVM template from the project root. So that output is aligned to the folder structure.
Note: Don't suffix anything to the name, it'll be included automatically.
dotnet new forms-mvvm -n Login -p:na MyApp
dotnet new forms-mvvm-cs -n Search -p:na MyApp
Output structure:
XAML:
ViewModels
LoginViewModel.cs
Views
LoginPage.xaml
LoginPage.xaml.cs
C#:
ViewModels
SearchViewModel.cs
Views
SearchPage.cs
v1.6.0:
1. Introduced an option to add a reference to Xamarin.Essentials.Interfaces NuGet package, an explicit option
2. Auto inclusion of the Type of the Item template that is created for Page, Shell, and Views
Just mention only the name of the item that is to be created. Item Type and File Extension would be automatically added.
dotnet new forms-page -n Home -p:na MyApp.Views
dotnet new forms-page-cs -n Settings -p:na MyApp.Views
dotnet new forms-view -n Card -p:na MyApp.Views
dotnet new forms-view-cs -n Order -p:na MyApp.Views
v1.5.0:
1. Introduced an option to add a reference to all supported NuGet packages by specifying a single parameter
-asp | --all-supported-packages -> The default value is false.
dotnet new formsclasslib -o FormsLib -asp
2. Option to reference the Shared Toolkit NuGet package
-ist | --include-shared-toolkit -> The default value is false.
dotnet new formsclasslib -o FormsLib -ist
3. Introduced an option to support the NuGet Central Package Management (CPM) feature
-cpm | --central-pkg-mgmt -> The default value is false.
dotnet new formsclasslib -o FormsLib -cpm
Note: For now, the CPM feature is only supported on CLI.
v1.4.4:
Package versions bumped to pull the latest stable version.
v1.4.3:
1. Package versions have been made dynamic to pull the latest stable version.
2. Added a new item template for Shell definition in C#
dotnet new forms-shell-cs -n AppShell -na MyLib
v1.4.2:
Little housekeeping to improve the reliability of the templates.
v1.4.1
Xamarin.Forms version bumped to 5.0.0.2515 (SR12).
Option to the choose the library target framework - .NET Standard 2.0 / 2.1
v1.4.0:
Included an option to add reference Xamarin.Essentials NuGet package during Xamarin.Forms class library creation.
Added new item templates for Forms Page and View in C#.
v1.3.1:
Included the IsExternalInit class definition to make use of C# 9.0 features such as Records.