Skip to content

Commit

Permalink
Merge pull request #66 from egvijayanand/working
Browse files Browse the repository at this point in the history
Added the option for configuring conditional compilation
  • Loading branch information
egvijayanand authored Jun 17, 2022
2 parents 10a7e74 + 3c54050 commit 77dfcde
Show file tree
Hide file tree
Showing 10 changed files with 174 additions and 11 deletions.
30 changes: 28 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Join me on [**Developer Thoughts**](https://egvijayanand.in/), an exclusive blog

We all know that .NET MAUI is an evolution of Xamarin.Forms.

The stable version `.NET MAUI GA` is now released on 23 May 2022 along with Visual Studio 2022 Version 17.3.0 Preview 1.1
The stable version `.NET MAUI SR1 (Service Release 1)` is now released on 14 Jun 2022 along with Visual Studio 2022 Version 17.3.0 Preview 2.0

Templates have been updated to support the latest release and is available to install from.

Expand Down Expand Up @@ -107,13 +107,25 @@ In .NET CLI, all of these templates takes two parameters:

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

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

*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`

All-in-One .NET MAUI App project takes one additional parameter to define the application design pattern:

Expand Down Expand Up @@ -179,6 +191,10 @@ Option to include NuGet packages:
```shell
dotnet new mauiapp -n MyApp -dp Shell -it -im -imt
```
Option to configure conditional compilation:
```shell
dotnet new mauiapp -n MyApp -dp Shell -cc
```

.NET MAUI Class Library:
```shell
Expand All @@ -188,6 +204,10 @@ Option to include NuGet packages:
```shell
dotnet new mauiclasslib -n MyApp.Core -it -im -imt
```
Option to configure conditional compilation:
```shell
dotnet new mauiclasslib -n MyApp.Core -cc
```

Shared Class Library:
```shell
Expand Down Expand Up @@ -234,6 +254,9 @@ Option to include NuGet packages:
```shell
dotnet new mauiapp --name MyApp --design-pattern Shell --include-toolkit --include-markup --include-mvvm-toolkit
```
```shell
dotnet new mauiapp -n MyApp --design-pattern Shell --conditional-compilation
```

.NET MAUI Class Library:
```shell
Expand All @@ -242,6 +265,9 @@ dotnet new mauiclasslib --name MyApp.Core
```shell
dotnet new mauiclasslib --name MyApp.Core --include-toolkit --include-markup --include-mvvm-toolkit
```
```shell
dotnet new mauiclasslib --name MyApp.Core --conditional-compilation
```

Shared Class Library:
```shell
Expand Down
8 changes: 8 additions & 0 deletions src/MauiTemplatesCLI/MauiAppX/.template.config/ide.host.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,14 @@
},
"isVisible": true,
"defaultValue": "false"
},
{
"id": "conditional-compilation",
"name": {
"text": "_Configure conditional compilation for the project"
},
"isVisible": true,
"defaultValue": "false"
}
]
}
10 changes: 10 additions & 0 deletions src/MauiTemplatesCLI/MauiAppX/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@
"description": "Option to add CommunityToolkit.Mvvm (aka Microsoft MVVM Toolkit) NuGet package reference.",
"displayName": "Add CommunityToolkit.Mvvm (aka Microsoft MV_VM Toolkit) NuGet package reference"
},
"conditional-compilation": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Option to configure conditional compilation so that platform source files can be anywhere."
},
"no-solution-file": {
"type": "parameter",
"datatype": "bool",
Expand Down Expand Up @@ -216,6 +222,10 @@
"type": "computed",
"value": "(include-mvvm-toolkit)"
},
"ConditionalCompilation": {
"type": "computed",
"value": "(conditional-compilation)"
},
"HostIdentifier": {
"type": "bind",
"binding": "HostIdentifier"
Expand Down
42 changes: 42 additions & 0 deletions src/MauiTemplatesCLI/MauiAppX/MauiApp1.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,46 @@
<!--#if (AddToolkitPackage || AddMarkupPackage || AddMvvmToolkitPackage)-->
</ItemGroup>
<!--#endif-->

<!--#if (ConditionalCompilation)-->
<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>
<!--#endif-->
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@
"defaultValue": "false"
},
{
"id": "no-solution-file",
"id": "conditional-compilation",
"name": {
"text": "Skip creating a solution file"
"text": "_Configure conditional compilation for the project"
},
"isVisible": false,
"isVisible": true,
"defaultValue": "false"
}
]
Expand Down
10 changes: 10 additions & 0 deletions src/MauiTemplatesCLI/MauiClassLib/.template.config/template.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@
"description": "Option to add CommunityToolkit.Mvvm (aka Microsoft MVVM Toolkit) NuGet package reference.",
"displayName": "Add CommunityToolkit.Mvvm (aka Microsoft MV_VM Toolkit) NuGet package reference"
},
"conditional-compilation": {
"type": "parameter",
"datatype": "bool",
"defaultValue": "false",
"description": "Option to configure conditional compilation so that platform source files can be anywhere."
},
"no-solution-file": {
"type": "parameter",
"datatype": "bool",
Expand All @@ -66,6 +72,10 @@
"type": "computed",
"value": "(include-mvvm-toolkit)"
},
"ConditionalCompilation": {
"type": "computed",
"value": "(conditional-compilation)"
},
"HostIdentifier": {
"type": "bind",
"binding": "HostIdentifier"
Expand Down
42 changes: 42 additions & 0 deletions src/MauiTemplatesCLI/MauiClassLib/MauiClassLib.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,46 @@
<!--#if (AddToolkitPackage || AddMarkupPackage || AddMvvmToolkitPackage)-->
</ItemGroup>
<!--#endif-->

<!--#if (ConditionalCompilation)-->
<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>
<!--#endif-->
</Project>
2 changes: 1 addition & 1 deletion src/MauiTemplatesCLI/PackageVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.7.1
1.7.2
20 changes: 20 additions & 0 deletions src/MauiTemplatesCLI/overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,23 @@ Use the below .NET CLI command to create the All-in-One .NET MAUI App, library p

Both .NET MAUI *App* and *Class Library* templates take the below optional Boolean parameters to include the officially supported CommunityToolkit NuGet packages:

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

*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`

All-in-One .NET MAUI App project takes one additional parameter to define the application design pattern:

Expand Down Expand Up @@ -101,6 +113,10 @@ Option to include NuGet packages:
```shell
dotnet new mauiapp -n MyApp -dp Shell -it -im -imt
```
Option to configure conditional compilation:
```shell
dotnet new mauiapp -n MyApp -dp Shell -cc
```

.NET MAUI Class Library:
```shell
Expand All @@ -110,6 +126,10 @@ Option to include NuGet packages:
```shell
dotnet new mauiclasslib -n MyApp.Core -it -im -imt
```
Option to configure conditional compilation:
```shell
dotnet new mauiclasslib -n MyApp.Core -cc
```

Shared Class Library:
```shell
Expand Down
15 changes: 10 additions & 5 deletions src/MauiTemplatesCLI/release-notes.txt
Original file line number Diff line number Diff line change
@@ -1,12 +1,17 @@
What's new in ver. 1.7.1:
What's new in ver. 1.7.2:
-------------------------
Introduced a new parameter to include all supported packages in the Shared Class Library template.
Added the option to configure conditional compilation so that platform source files can be defined anywhere in the project provided they follow a naming convention as mentioned below.

-asp | --all-supported-packages
This will allow maintaining related source files in the same place, especially MAUI Handlers.

Which will add reference to all 6 supported NuGet packages.
*.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

Included IsExternalInit type definition to support C# Records while compiling for Xamarin.Forms
Parameter name: -cc | --conditional-compilation

Templates have been updated to .NET MAUI GA, stable release version.

Expand Down

0 comments on commit 77dfcde

Please sign in to comment.