Skip to content

Commit

Permalink
Merge pull request #22 from egvijayanand/working
Browse files Browse the repository at this point in the history
Essentials Interfaces and Auto type inclusion
  • Loading branch information
egvijayanand authored Jan 12, 2024
2 parents b9b1cc7 + c71f5ca commit 3496fb8
Show file tree
Hide file tree
Showing 22 changed files with 226 additions and 99 deletions.
64 changes: 42 additions & 22 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dotnet new update

#### Templates Included

Project template for Xamarin.Forms Class Library and is named as `formsclasslib`
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 supported [Xamarin.CommunityToolkit](https://www.nuget.org/packages/Xamarin.CommunityToolkit), [Xamarin.CommunityToolkit.Markup](https://www.nuget.org/packages/Xamarin.CommunityToolkit.Markup), [Xamarin.Essentials](https://www.nuget.org/packages/Xamarin.Essentials), [CommunityToolkit.Mvvm](https://www.nuget.org/packages/CommunityToolkit.Mvvm) (aka Microsoft MVVM Toolkit), [VijayAnand.Toolkit.Markup](https://www.nuget.org/packages/VijayAnand.Toolkit.Markup) (the Shared Toolkit) or all NuGet packages:

Expand All @@ -57,6 +57,10 @@ Class library project template take the below optional parameters to override it
* `-imt` | `--include-mvvm-toolkit` - Default value is `false`
* `-ist` | `--include-shared-toolkit` - Default value is `false`

Explicit option:

* `-iei` | `--include-essentials-interfaces` - Default value is `false`

*Note: The NuGet package version being added out-of-the-box are v2.0.x for the Xamarin Toolkit packages, v1.8.x for the Xamarin.Essentials package, and v8.2.x for the MVVM Toolkit package.*

|Item|Template Name|
Expand All @@ -71,69 +75,85 @@ Class library project template take the below optional parameters to override it

Use the below .NET CLI command to create the project, pages, and views out these templates:

Here, `-n` denotes the name of the project/page/view that is to be created (for pages/views, don't need to suffix it with `.xaml` / `.cs`, it will be added automatically) (Can also be specified as `--name` in the expanded form).

*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:`).*

Class Library:

```shell
dotnet new formsclasslib -n MyApp.Core
dotnet new formsclasslib -o MyApp.Core
```

Library target framework override:

```shell
dotnet new formsclasslib -n MyApp.Core -f netstandard2.1
dotnet new formsclasslib -o MyApp.Core -f netstandard2.1
```

Option to include NuGet packages:

```shell
dotnet new formsclasslib -n MyApp.UI -it -im -ie -imt -ist
dotnet new formsclasslib -o MyApp.UI -it -im -ie -iei -imt -ist
```
In a single parameter:

In a single parameter (Essentials Interfaces is an exception, to be explicitly mentioned):

```shell
dotnet new formsclasslib -n MyApp.UI -asp
dotnet new formsclasslib -o MyApp.UI -asp -iei
```

NuGet Central Package Management (CPM) feature:

_For now, this is supported only on CLI. Can be used in combination with other parameters too._

```shell
dotnet new formsclasslib -n MyApp.UI -cpm
dotnet new formsclasslib -o MyApp.UI -cpm
```

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:`).*

Page:

```shell
dotnet new forms-page -n LoginPage -na MyApp.Views
dotnet new forms-page -n Login -na MyApp.Views
```
```shell
dotnet new forms-page-cs -n HomePage -na MyApp.Views
dotnet new forms-page-cs -n Home -na MyApp.Views
```

View:

```shell
dotnet new forms-view -n CardView -na MyApp.Views
dotnet new forms-view -n Card -na MyApp.Views
```
```shell
dotnet new forms-view-cs -n ContactsView -na MyApp.Views
dotnet new forms-view-cs -n Order -na MyApp.Views
```

Shell:

```shell
dotnet new forms-shell -n AppShell -na MyApp
dotnet new forms-shell -n App -na MyApp
```
```shell
dotnet new forms-shell-cs -n MobileShell -na MyApp
dotnet new forms-shell-cs -n Mobile -na MyApp
```

Resource Dictionary:

With C# code-behind file:

```shell
dotnet new forms-resdict -n DefaultTheme -na MyApp.Themes
```
Without C# code-behind file - Xaml only (Option can be specified as `-xo` or `--xaml-only`):

Without C# code-behind file - Xaml only (The option to be specified is `-xo` or `--xaml-only`):

```shell
dotnet new forms-resdict -n DarkTheme -na MyApp.Themes -xo
```
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@
"isVisible": true,
"defaultValue": "false"
},
{
"id": "include-essentials-interfaces",
"name": {
"text": "Add Xamarin.Essentials._Interfaces NuGet package reference"
},
"isVisible": true,
"defaultValue": "false"
},
{
"id": "include-mvvm-toolkit",
"name": {
Expand Down
20 changes: 15 additions & 5 deletions src/FormsTemplatesCLI/FormsClassLib/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@
"defaultValue": "false",
"description": "If true, includes reference to the Xamarin.Essentials NuGet package."
},
"include-essentials-interfaces": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "If true, includes reference to the Xamarin.Essentials.Interfaces NuGet package."
},
"include-mvvm-toolkit": {
"type": "parameter",
"datatype": "bool",
Expand All @@ -95,23 +101,27 @@
"defaultValue": "false",
"description": "Option to skip creating a solution file."
},
"AddToolkitPackage": {
"AddToolkit": {
"type": "computed",
"value": "(include-toolkit || all-supported-packages)"
},
"AddMarkupPackage": {
"AddMarkup": {
"type": "computed",
"value": "(include-markup || all-supported-packages)"
},
"AddEssentialsPackage": {
"AddEssentials": {
"type": "computed",
"value": "(include-essentials || all-supported-packages)"
},
"AddMvvmToolkitPackage": {
"AddEssentialsInterfaces": {
"type": "computed",
"value": "(include-essentials-interfaces)"
},
"AddMvvmToolkit": {
"type": "computed",
"value": "(include-mvvm-toolkit || all-supported-packages)"
},
"AddSharedToolkitPackage": {
"AddSharedToolkit": {
"type": "computed",
"value": "(include-shared-toolkit || all-supported-packages)"
},
Expand Down
5 changes: 1 addition & 4 deletions src/FormsTemplatesCLI/FormsClassLib/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,5 @@

namespace System.Runtime.CompilerServices
{
internal class IsExternalInit
{

}
internal class IsExternalInit { }
}
7 changes: 0 additions & 7 deletions src/FormsTemplatesCLI/FormsClassLib/Class1.cs

This file was deleted.

17 changes: 10 additions & 7 deletions src/FormsTemplatesCLI/FormsClassLib/Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,23 @@
</PropertyGroup>
<ItemGroup>
<PackageVersion Include="Xamarin.Forms" Version="5.0.0.2622" />
<!--#if (AddEssentialsPackage)-->
<PackageVersion Include="Xamarin.Essentials" Version="1.8.0" />
<!--#if (AddEssentials)-->
<PackageVersion Include="Xamarin.Essentials" Version="1.8.1" />
<!--#endif-->
<!--#if (AddToolkitPackage)-->
<!--#if (AddEssentialsInterfaces)-->
<PackageVersion Include="Xamarin.Essentials.Interfaces" Version="1.8.0" />
<!--#endif-->
<!--#if (AddToolkit)-->
<PackageVersion Include="Xamarin.CommunityToolkit" Version="2.0.6" />
<!--#endif-->
<!--#if (AddMarkupPackage)-->
<!--#if (AddMarkup)-->
<PackageVersion Include="Xamarin.CommunityToolkit.Markup" Version="2.0.6" />
<!--#endif-->
<!--#if (AddMvvmToolkitPackage)-->
<!--#if (AddMvvmToolkit)-->
<PackageVersion Include="CommunityToolkit.Mvvm" Version="8.2.2" />
<!--#endif-->
<!--#if (AddSharedToolkitPackage)-->
<PackageVersion Include="VijayAnand.Toolkit.Markup" Version="3.0.0" />
<!--#if (AddSharedToolkit)-->
<PackageVersion Include="VijayAnand.Toolkit.Markup" Version="3.2.0" />
<!--#endif-->
</ItemGroup>
</Project>
26 changes: 16 additions & 10 deletions src/FormsTemplatesCLI/FormsClassLib/FormsClassLib.1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,42 @@
<ItemGroup>
<!--#if (CentralPkgMgmt)-->
<PackageReference Include="Xamarin.Forms" />
<!--#if (AddToolkitPackage)-->
<!--#if (AddToolkit)-->
<PackageReference Include="Xamarin.CommunityToolkit" />
<!--#endif-->
<!--#if (AddMarkupPackage)-->
<!--#if (AddMarkup)-->
<PackageReference Include="Xamarin.CommunityToolkit.Markup" />
<!--#endif-->
<!--#if (AddEssentialsPackage)-->
<!--#if (AddEssentials)-->
<PackageReference Include="Xamarin.Essentials" />
<!--#endif-->
<!--#if (AddMvvmToolkitPackage)-->
<!--#if (AddEssentialsInterfaces)-->
<PackageReference Include="Xamarin.Essentials.Interfaces" />
<!--#endif-->
<!--#if (AddMvvmToolkit)-->
<PackageReference Include="CommunityToolkit.Mvvm" />
<!--#endif-->
<!--#if (AddSharedToolkitPackage)-->
<!--#if (AddSharedToolkit)-->
<PackageReference Include="VijayAnand.Toolkit.Markup" />
<!--#endif-->
<!--#else-->
<PackageReference Include="Xamarin.Forms" Version="5.*" />
<!--#if (AddToolkitPackage)-->
<!--#if (AddToolkit)-->
<PackageReference Include="Xamarin.CommunityToolkit" Version="2.*" />
<!--#endif-->
<!--#if (AddMarkupPackage)-->
<!--#if (AddMarkup)-->
<PackageReference Include="Xamarin.CommunityToolkit.Markup" Version="2.*" />
<!--#endif-->
<!--#if (AddEssentialsPackage)-->
<!--#if (AddEssentials)-->
<PackageReference Include="Xamarin.Essentials" Version="1.*" />
<!--#endif-->
<!--#if (AddMvvmToolkitPackage)-->
<!--#if (AddEssentialsInterfaces)-->
<PackageReference Include="Xamarin.Essentials.Interfaces" Version="1.*" />
<!--#endif-->
<!--#if (AddMvvmToolkit)-->
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.*" />
<!--#endif-->
<!--#if (AddSharedToolkitPackage)-->
<!--#if (AddSharedToolkit)-->
<PackageReference Include="VijayAnand.Toolkit.Markup" Version="3.*" />
<!--#endif-->
<!--#endif-->
Expand Down
54 changes: 54 additions & 0 deletions src/FormsTemplatesCLI/FormsClassLib/HomePage.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using Xamarin.Forms;
using Xamarin.Forms.Xaml;
#if (AddEssentials || AddEssentialsInterfaces)

using Xamarin.Essentials;
#endif
#if AddEssentialsInterfaces
using Xamarin.Essentials.Implementation;
using Xamarin.Essentials.Interfaces;
#endif
#if AddToolkit

using Xamarin.CommunityToolkit.Behaviors;
using Xamarin.CommunityToolkit.Converters;
using Xamarin.CommunityToolkit.Effects;
using Xamarin.CommunityToolkit.ObjectModel;
using Xamarin.CommunityToolkit.UI.Views;
#endif
#if AddMarkup

using Xamarin.CommunityToolkit.Markup;
#endif
#if AddMvvmToolkit

using CommunityToolkit.Mvvm.ComponentModel;
using CommunityToolkit.Mvvm.Input;
using CommunityToolkit.Mvvm.Messaging;
#endif
#if AddSharedToolkit

using VijayAnand.Toolkit.Markup;
#endif
#if AddSharedToolkit

// Static
using static Xamarin.CommunityToolkit.Markup.GridRowsColumns;
using static VijayAnand.Toolkit.Markup.ResourceHelper;
using static VijayAnand.Toolkit.Markup.VisualStateHelper;
#elif AddMarkup

// Static
using static Xamarin.CommunityToolkit.Markup.GridRowsColumns;
#endif

namespace FormsClassLib._1
{
public class HomePage : ContentPage
{
public HomePage()
{

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"path": "FormsPage.1.xaml"
},
{
"path": "FormsPage.1.xaml.cs",
"path": "FormsPage.1Page.xaml.cs",
"condition": "(!XamlOnly)"
}
],
Expand Down Expand Up @@ -54,7 +54,7 @@
{
"condition": "(XamlOnly)",
"exclude": [
"FormsPage.1.xaml.cs"
"FormsPage.1Page.xaml.cs"
]
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mc:Ignorable="d">
<!--#else-->
<ContentPage
x:Class="MyApp.Namespace.FormsPage__1"
x:Class="MyApp.Namespace.FormsPage__1Page"
xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:d="http://xamarin.com/schemas/2014/forms/design"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
namespace MyApp.Namespace
{
[XamlCompilation(XamlCompilationOptions.Compile)]
public partial class FormsView__1 : ContentView
public partial class FormsPage__1Page : ContentPage
{
public FormsView__1()
public FormsPage__1Page()
{
InitializeComponent();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace MyApp.Namespace
{
public partial class FormsView__1 : ContentView
public partial class FormsPage__1Page : ContentPage
{
public FormsView__1()
public FormsPage__1Page()
{
Content = new StackLayout()
{
Expand Down
Loading

0 comments on commit 3496fb8

Please sign in to comment.