From 74f2bd91201b11d8f4b6f39806a2cd561517bc71 Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Mon, 6 May 2024 14:24:37 +0200 Subject: [PATCH 01/10] - add option to use CommunityToolkit.Mvvm - make ViewModelBase abstract - make MainWindowViewModel partial --- readme.md | 8 +++++++ .../.template.config/dotnetcli.host.json | 5 +++- .../xplat/.template.config/ide.host.json | 7 ++++++ .../xplat/.template.config/template.json | 24 +++++++++++++++++++ .../AvaloniaTest.Android/MainActivity.cs | 6 +++++ .../xplat/AvaloniaTest.Browser/Program.cs | 2 ++ .../xplat/AvaloniaTest.Desktop/Program.cs | 6 +++-- .../xplat/AvaloniaTest.iOS/AppDelegate.cs | 4 ++++ .../csharp/xplat/AvaloniaTest/App.axaml.cs | 9 +++++++ .../xplat/AvaloniaTest/AvaloniaTest.csproj | 5 ++++ .../AvaloniaTest/ViewModels/MainViewModel.cs | 17 +++++++++++-- .../AvaloniaTest/ViewModels/ViewModelBase.cs | 12 ++++++++-- 12 files changed, 98 insertions(+), 7 deletions(-) diff --git a/readme.md b/readme.md index f035cc42..0e924057 100644 --- a/readme.md +++ b/readme.md @@ -151,6 +151,14 @@ Available parameters: *By default*: true +``-m, --mvvm`` + +*Description*: MVVM toolkit to use in the template. + +*Options*: **ReactiveUI**, **CommunityToolkit** + +*By default*: ReactiveUI + ``-av, --avalonia-version`` *Description*: The target version of Avalonia NuGet packages. diff --git a/templates/csharp/xplat/.template.config/dotnetcli.host.json b/templates/csharp/xplat/.template.config/dotnetcli.host.json index d68268f6..b4e57786 100644 --- a/templates/csharp/xplat/.template.config/dotnetcli.host.json +++ b/templates/csharp/xplat/.template.config/dotnetcli.host.json @@ -10,11 +10,14 @@ "UseCompiledBindings": { "longName": "compiled-bindings" }, + "MVVMToolkit": { + "longName": "mvvm" + }, "RemoveViewLocator": { "longName": "remove-view-locator" } }, "usageExamples": [ - "" + "--mvvm communitytoolkit" ] } \ No newline at end of file diff --git a/templates/csharp/xplat/.template.config/ide.host.json b/templates/csharp/xplat/.template.config/ide.host.json index 287ea1de..4774aa44 100644 --- a/templates/csharp/xplat/.template.config/ide.host.json +++ b/templates/csharp/xplat/.template.config/ide.host.json @@ -9,6 +9,13 @@ }, "isVisible": true }, + { + "id": "MVVMToolkit", + "name": { + "text": "MVVM Toolkit" + }, + "isVisible": true + }, { "id": "UseCompiledBindings", "name": { diff --git a/templates/csharp/xplat/.template.config/template.json b/templates/csharp/xplat/.template.config/template.json index 4772dbc1..c236ca63 100644 --- a/templates/csharp/xplat/.template.config/template.json +++ b/templates/csharp/xplat/.template.config/template.json @@ -28,6 +28,30 @@ "replaces": "FrameworkParameter", "defaultValue": "net8.0" }, + "MVVMToolkit": { + "type": "parameter", + "description": "MVVM toolkit to use in the template.", + "datatype": "choice", + "choices": [ + { + "choice": "ReactiveUI", + "description": "Choose ReactiveUI as MVVM toolkit in the template." + }, + { + "choice": "CommunityToolkit", + "description": "Choose CommunityToolkit as MVVM toolkit in the template." + } + ], + "defaultValue": "ReactiveUI" + }, + "ReactiveUIToolkitChosen": { + "type": "computed", + "value": "(MVVMToolkit == \"ReactiveUI\")" + }, + "CommunityToolkitChosen": { + "type": "computed", + "value": "(MVVMToolkit == \"CommunityToolkit\")" + }, "AvaloniaVersion": { "type": "parameter", "description": "The target version of Avalonia NuGet packages.", diff --git a/templates/csharp/xplat/AvaloniaTest.Android/MainActivity.cs b/templates/csharp/xplat/AvaloniaTest.Android/MainActivity.cs index 9ac57834..b7f9d82f 100644 --- a/templates/csharp/xplat/AvaloniaTest.Android/MainActivity.cs +++ b/templates/csharp/xplat/AvaloniaTest.Android/MainActivity.cs @@ -2,7 +2,9 @@ using Android.Content.PM; using Avalonia; using Avalonia.Android; +#if (ReactiveUIToolkitChosen) using Avalonia.ReactiveUI; +#endif namespace AvaloniaTest.Android; @@ -17,7 +19,11 @@ public class MainActivity : AvaloniaMainActivity protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) { return base.CustomizeAppBuilder(builder) +#if (CommunityToolkitChosen) + .WithInterFont(); +#else .WithInterFont() .UseReactiveUI(); +#endif } } diff --git a/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs b/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs index e0ab2612..48e367cd 100644 --- a/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs +++ b/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs @@ -11,7 +11,9 @@ internal sealed partial class Program { private static Task Main(string[] args) => BuildAvaloniaApp() .WithInterFont() +#if (ReactiveUIToolkitChosen) .UseReactiveUI() +#endif .StartBrowserAppAsync("out"); public static AppBuilder BuildAvaloniaApp() diff --git a/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs b/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs index 080b0f61..21cc8d68 100644 --- a/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs +++ b/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs @@ -18,6 +18,8 @@ public static AppBuilder BuildAvaloniaApp() => AppBuilder.Configure() .UsePlatformDetect() .WithInterFont() - .LogToTrace() - .UseReactiveUI(); +#if (ReactiveUIToolkitChosen) + .UseReactiveUI() +#endif + .LogToTrace(); } diff --git a/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs b/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs index 6612b3ee..9035a369 100644 --- a/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs +++ b/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs @@ -19,7 +19,11 @@ public partial class AppDelegate : AvaloniaAppDelegate protected override AppBuilder CustomizeAppBuilder(AppBuilder builder) { return base.CustomizeAppBuilder(builder) +#if (CommunityToolkitChosen) + .WithInterFont(); +#else .WithInterFont() .UseReactiveUI(); +#endif } } diff --git a/templates/csharp/xplat/AvaloniaTest/App.axaml.cs b/templates/csharp/xplat/AvaloniaTest/App.axaml.cs index 5530a141..7e4f8ebe 100644 --- a/templates/csharp/xplat/AvaloniaTest/App.axaml.cs +++ b/templates/csharp/xplat/AvaloniaTest/App.axaml.cs @@ -1,5 +1,9 @@ using Avalonia; using Avalonia.Controls.ApplicationLifetimes; +#if (CommunityToolkitChosen) +using Avalonia.Data.Core; +using Avalonia.Data.Core.Plugins; +#endif using Avalonia.Markup.Xaml; using AvaloniaTest.ViewModels; using AvaloniaTest.Views; @@ -17,6 +21,11 @@ public override void OnFrameworkInitializationCompleted() { if (ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop) { +#if (CommunityToolkitChosen) + // Line below is needed to remove Avalonia data validation. + // Without this line you will get duplicate validations from both Avalonia and CT + BindingPlugins.DataValidators.RemoveAt(0); +#endif desktop.MainWindow = new MainWindow { DataContext = new MainViewModel() diff --git a/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj b/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj index 10934d0e..0b4b589e 100644 --- a/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj +++ b/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj @@ -19,5 +19,10 @@ + + + + + diff --git a/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs b/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs index 2daa637d..b0331fcd 100644 --- a/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs +++ b/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs @@ -1,8 +1,21 @@ -namespace AvaloniaTest.ViewModels; +#if (CommunityToolkitChosen) +using CommunityToolkit.Mvvm.ComponentModel; +#endif -public class MainViewModel : ViewModelBase +namespace AvaloniaTest.ViewModels; + +#if (CommunityToolkitChosen) +public partial class MainWindowViewModel : ViewModelBase +#else +public class MainWindowViewModel : ViewModelBase +#endif { +#if (CommunityToolkitChosen) + [ObservableProperty] + private string _greeting = "Welcome to Avalonia!"; +#else #pragma warning disable CA1822 // Mark members as static public string Greeting => "Welcome to Avalonia!"; #pragma warning restore CA1822 // Mark members as static +#endif } diff --git a/templates/csharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.cs b/templates/csharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.cs index 3b1a38de..d0e973a9 100644 --- a/templates/csharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.cs +++ b/templates/csharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.cs @@ -1,7 +1,15 @@ -using ReactiveUI; +#if (CommunityToolkitChosen) +using CommunityToolkit.Mvvm.ComponentModel; +#elif (ReactiveUIToolkitChosen) +using ReactiveUI; +#endif namespace AvaloniaTest.ViewModels; -public class ViewModelBase : ReactiveObject +#if (CommunityToolkitChosen) +public abstract class ViewModelBase : ObservableObject +#elif (ReactiveUIToolkitChosen) +public abstract class ViewModelBase : ReactiveObject +#endif { } From 62d63287952c3d766ee39dcfff565d69f7c0e52f Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Mon, 6 May 2024 14:25:22 +0200 Subject: [PATCH 02/10] edit fsharp tamplates --- .../app-mvvm/ViewModels/ViewModelBase.fs | 1 + .../.template.config/dotnetcli.host.json | 5 +++- .../xplat/.template.config/ide.host.json | 7 ++++++ .../xplat/.template.config/template.json | 24 +++++++++++++++++++ .../xplat/AvaloniaTest.Android/Activities.fs | 4 ++++ .../xplat/AvaloniaTest.Browser/Program.fs | 5 +++- .../xplat/AvaloniaTest.Desktop/Program.fs | 4 ++++ .../xplat/AvaloniaTest.iOS/AppDelegate.fs | 6 ++++- .../fsharp/xplat/AvaloniaTest/App.axaml.fs | 11 +++++++++ .../xplat/AvaloniaTest/AvaloniaTest.fsproj | 5 ++++ .../AvaloniaTest/ViewModels/ViewModelBase.fs | 9 +++++++ 11 files changed, 78 insertions(+), 3 deletions(-) diff --git a/templates/fsharp/app-mvvm/ViewModels/ViewModelBase.fs b/templates/fsharp/app-mvvm/ViewModels/ViewModelBase.fs index fc704833..cd8ef1a8 100644 --- a/templates/fsharp/app-mvvm/ViewModels/ViewModelBase.fs +++ b/templates/fsharp/app-mvvm/ViewModels/ViewModelBase.fs @@ -6,6 +6,7 @@ open CommunityToolkit.Mvvm.ComponentModel open ReactiveUI #endif +[] type ViewModelBase() = #if (CommunityToolkitChosen) inherit ObservableObject() diff --git a/templates/fsharp/xplat/.template.config/dotnetcli.host.json b/templates/fsharp/xplat/.template.config/dotnetcli.host.json index d68268f6..b4e57786 100644 --- a/templates/fsharp/xplat/.template.config/dotnetcli.host.json +++ b/templates/fsharp/xplat/.template.config/dotnetcli.host.json @@ -10,11 +10,14 @@ "UseCompiledBindings": { "longName": "compiled-bindings" }, + "MVVMToolkit": { + "longName": "mvvm" + }, "RemoveViewLocator": { "longName": "remove-view-locator" } }, "usageExamples": [ - "" + "--mvvm communitytoolkit" ] } \ No newline at end of file diff --git a/templates/fsharp/xplat/.template.config/ide.host.json b/templates/fsharp/xplat/.template.config/ide.host.json index 287ea1de..4774aa44 100644 --- a/templates/fsharp/xplat/.template.config/ide.host.json +++ b/templates/fsharp/xplat/.template.config/ide.host.json @@ -9,6 +9,13 @@ }, "isVisible": true }, + { + "id": "MVVMToolkit", + "name": { + "text": "MVVM Toolkit" + }, + "isVisible": true + }, { "id": "UseCompiledBindings", "name": { diff --git a/templates/fsharp/xplat/.template.config/template.json b/templates/fsharp/xplat/.template.config/template.json index 05679f66..8438a2f2 100644 --- a/templates/fsharp/xplat/.template.config/template.json +++ b/templates/fsharp/xplat/.template.config/template.json @@ -28,6 +28,30 @@ "replaces": "FrameworkParameter", "defaultValue": "net8.0" }, + "MVVMToolkit": { + "type": "parameter", + "description": "MVVM toolkit to use in the template.", + "datatype": "choice", + "choices": [ + { + "choice": "ReactiveUI", + "description": "Choose ReactiveUI as MVVM toolkit in the template." + }, + { + "choice": "CommunityToolkit", + "description": "Choose CommunityToolkit as MVVM toolkit in the template." + } + ], + "defaultValue": "ReactiveUI" + }, + "ReactiveUIToolkitChosen": { + "type": "computed", + "value": "(MVVMToolkit == \"ReactiveUI\")" + }, + "CommunityToolkitChosen": { + "type": "computed", + "value": "(MVVMToolkit == \"CommunityToolkit\")" + }, "AvaloniaVersion": { "type": "parameter", "description": "The target version of Avalonia NuGet packages.", diff --git a/templates/fsharp/xplat/AvaloniaTest.Android/Activities.fs b/templates/fsharp/xplat/AvaloniaTest.Android/Activities.fs index b194fca1..0ac84a2d 100644 --- a/templates/fsharp/xplat/AvaloniaTest.Android/Activities.fs +++ b/templates/fsharp/xplat/AvaloniaTest.Android/Activities.fs @@ -3,7 +3,9 @@ namespace AvaloniaTest.Android open Android.App open Android.Content.PM open Avalonia +#if (ReactiveUIToolkitChosen) open Avalonia.ReactiveUI +#endif open Avalonia.Android open AvaloniaTest @@ -19,4 +21,6 @@ type MainActivity() = override _.CustomizeAppBuilder(builder) = base.CustomizeAppBuilder(builder) .WithInterFont() +#if (ReactiveUIToolkitChosen) .UseReactiveUI() +#endif diff --git a/templates/fsharp/xplat/AvaloniaTest.Browser/Program.fs b/templates/fsharp/xplat/AvaloniaTest.Browser/Program.fs index f115d515..66cbee26 100644 --- a/templates/fsharp/xplat/AvaloniaTest.Browser/Program.fs +++ b/templates/fsharp/xplat/AvaloniaTest.Browser/Program.fs @@ -1,8 +1,9 @@ open System.Runtime.Versioning open Avalonia open Avalonia.Browser +#if (ReactiveUIToolkitChosen) open Avalonia.ReactiveUI - +#endif open AvaloniaTest module Program = @@ -19,7 +20,9 @@ module Program = task { do! (buildAvaloniaApp() .WithInterFont() +#if (ReactiveUIToolkitChosen) .UseReactiveUI() +#endif .StartBrowserAppAsync("out")) } |> ignore diff --git a/templates/fsharp/xplat/AvaloniaTest.Desktop/Program.fs b/templates/fsharp/xplat/AvaloniaTest.Desktop/Program.fs index 556fe3f3..5b91bda9 100644 --- a/templates/fsharp/xplat/AvaloniaTest.Desktop/Program.fs +++ b/templates/fsharp/xplat/AvaloniaTest.Desktop/Program.fs @@ -1,7 +1,9 @@ namespace AvaloniaTest.Desktop open System open Avalonia +#if (ReactiveUIToolkitChosen) open Avalonia.ReactiveUI +#endif open AvaloniaTest module Program = @@ -13,7 +15,9 @@ module Program = .UsePlatformDetect() .WithInterFont() .LogToTrace(areas = Array.empty) +#if (ReactiveUIToolkitChosen) .UseReactiveUI() +#endif [] let main argv = diff --git a/templates/fsharp/xplat/AvaloniaTest.iOS/AppDelegate.fs b/templates/fsharp/xplat/AvaloniaTest.iOS/AppDelegate.fs index d956cff2..81101d87 100644 --- a/templates/fsharp/xplat/AvaloniaTest.iOS/AppDelegate.fs +++ b/templates/fsharp/xplat/AvaloniaTest.iOS/AppDelegate.fs @@ -2,7 +2,9 @@ namespace AvaloniaTest.iOS open Foundation open Avalonia open Avalonia.iOS +#if (ReactiveUIToolkitChosen) open Avalonia.ReactiveUI +#endif // The UIApplicationDelegate for the application. This class is responsible for launching the // User Interface of the application, as well as listening (and optionally responding) to @@ -13,4 +15,6 @@ type [] AppDelegate() = override _.CustomizeAppBuilder(builder) = base.CustomizeAppBuilder(builder) .WithInterFont() - .UseReactiveUI() \ No newline at end of file +#if (ReactiveUIToolkitChosen) + .UseReactiveUI() +#endif \ No newline at end of file diff --git a/templates/fsharp/xplat/AvaloniaTest/App.axaml.fs b/templates/fsharp/xplat/AvaloniaTest/App.axaml.fs index 580581d9..411560cc 100644 --- a/templates/fsharp/xplat/AvaloniaTest/App.axaml.fs +++ b/templates/fsharp/xplat/AvaloniaTest/App.axaml.fs @@ -2,6 +2,10 @@ namespace AvaloniaTest open Avalonia open Avalonia.Controls.ApplicationLifetimes +#if (CommunityToolkitChosen) +open Avalonia.Data.Core +open Avalonia.Data.Core.Plugins +#endif open Avalonia.Markup.Xaml open AvaloniaTest.ViewModels open AvaloniaTest.Views @@ -13,6 +17,13 @@ type App() = AvaloniaXamlLoader.Load(this) override this.OnFrameworkInitializationCompleted() = + +#if (CommunityToolkitChosen) + // Line below is needed to remove Avalonia data validation. + // Without this line you will get duplicate validations from both Avalonia and CT + BindingPlugins.DataValidators.RemoveAt(0) +#endif + match this.ApplicationLifetime with | :? IClassicDesktopStyleApplicationLifetime as desktopLifetime -> desktopLifetime.MainWindow <- MainWindow(DataContext = MainViewModel()) diff --git a/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj b/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj index 4ef74f7e..2e62cb6a 100644 --- a/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj +++ b/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj @@ -30,5 +30,10 @@ + + + + + diff --git a/templates/fsharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.fs b/templates/fsharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.fs index c64d6679..ea73aff4 100644 --- a/templates/fsharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.fs +++ b/templates/fsharp/xplat/AvaloniaTest/ViewModels/ViewModelBase.fs @@ -1,6 +1,15 @@ namespace AvaloniaTest.ViewModels +#if (CommunityToolkitChosen) +open CommunityToolkit.Mvvm.ComponentModel +#elif (ReactiveUIToolkitChosen) open ReactiveUI +#endif +[] type ViewModelBase() = +#if (CommunityToolkitChosen) + inherit ObservableObject() +#elif (ReactiveUIToolkitChosen) inherit ReactiveObject() +#endif From 7983300442c67480f84a156e593bd9abd266a7ac Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Mon, 6 May 2024 15:44:00 +0200 Subject: [PATCH 03/10] fix duplicate PackageReference --- templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj b/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj index 0b4b589e..d190c762 100644 --- a/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj +++ b/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj @@ -15,8 +15,7 @@ - - + From a59f654bc07aec1ae82f3ad23cde2220d0bc7b1e Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Mon, 6 May 2024 16:03:36 +0200 Subject: [PATCH 04/10] fix wrong name --- .../csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs b/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs index b0331fcd..a48feba4 100644 --- a/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs +++ b/templates/csharp/xplat/AvaloniaTest/ViewModels/MainViewModel.cs @@ -5,9 +5,9 @@ namespace AvaloniaTest.ViewModels; #if (CommunityToolkitChosen) -public partial class MainWindowViewModel : ViewModelBase +public partial class MainViewModel : ViewModelBase #else -public class MainWindowViewModel : ViewModelBase +public class MainViewModel : ViewModelBase #endif { #if (CommunityToolkitChosen) From 05d332ea817d870a13a98e07a062b1ee956a025d Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Mon, 6 May 2024 18:42:32 +0200 Subject: [PATCH 05/10] fix build error --- templates/csharp/xplat/AvaloniaTest.Browser/Program.cs | 2 ++ templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs | 2 ++ templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs | 2 ++ 3 files changed, 6 insertions(+) diff --git a/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs b/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs index 48e367cd..94035fbd 100644 --- a/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs +++ b/templates/csharp/xplat/AvaloniaTest.Browser/Program.cs @@ -2,7 +2,9 @@ using System.Threading.Tasks; using Avalonia; using Avalonia.Browser; +#if (ReactiveUIToolkitChosen) using Avalonia.ReactiveUI; +#endif using AvaloniaTest; [assembly: SupportedOSPlatform("browser")] diff --git a/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs b/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs index 21cc8d68..78e2a12b 100644 --- a/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs +++ b/templates/csharp/xplat/AvaloniaTest.Desktop/Program.cs @@ -1,6 +1,8 @@ using System; using Avalonia; +#if (ReactiveUIToolkitChosen) using Avalonia.ReactiveUI; +#endif namespace AvaloniaTest.Desktop; diff --git a/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs b/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs index 9035a369..1e0bdff6 100644 --- a/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs +++ b/templates/csharp/xplat/AvaloniaTest.iOS/AppDelegate.cs @@ -4,7 +4,9 @@ using Avalonia.Controls; using Avalonia.iOS; using Avalonia.Media; +#if (ReactiveUIToolkitChosen) using Avalonia.ReactiveUI; +#endif namespace AvaloniaTest.iOS; From bd1980f754a1a4a53766b761a4eb9b238631d74a Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Mon, 6 May 2024 18:43:02 +0200 Subject: [PATCH 06/10] edit build-test script --- tests/build-test.ps1 | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/build-test.ps1 b/tests/build-test.ps1 index 11ce6593..8ab803e2 100644 --- a/tests/build-test.ps1 +++ b/tests/build-test.ps1 @@ -113,19 +113,21 @@ Create-And-Build "avalonia.mvvm" "AvaloniaMvvm" "C#" "rvl" "false" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "f" "net8.0" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "av" "11.1.0-beta1" $binlog +Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "m" "ReactiveUI" $binlog +Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "m" "CommunityToolkit" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "cb" "true" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "cb" "false" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "rvl" "true" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "rvl" "false" $binlog +Remove-Item -Recurse "output/C#" + Create-And-Build "avalonia.app" "AvaloniaApp" "F#" "f" "net8.0" $binlog Create-And-Build "avalonia.app" "AvaloniaApp" "F#" "av" "11.0.10" $binlog Create-And-Build "avalonia.app" "AvaloniaApp" "F#" "av" "11.1.0-beta1" $binlog Create-And-Build "avalonia.app" "AvaloniaApp" "F#" "cb" "true" $binlog Create-And-Build "avalonia.app" "AvaloniaApp" "F#" "cb" "false" $binlog -Remove-Item -Recurse "output/C#" - Test-Template "avalonia.mvvm" "AvaloniaMvvm" "F#" "f" "net8.0" $binlog Create-And-Build "avalonia.mvvm" "AvaloniaMvvm" "F#" "av" "11.0.10" $binlog Create-And-Build "avalonia.mvvm" "AvaloniaMvvm" "F#" "av" "11.1.0-beta1" $binlog @@ -138,7 +140,11 @@ Create-And-Build "avalonia.mvvm" "AvaloniaMvvm" "F#" "rvl" "false" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "f" "net8.0" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "av" "11.1.0-beta1" $binlog +Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "m" "ReactiveUI" $binlog +Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "m" "CommunityToolkit" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "cb" "true" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "cb" "false" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "rvl" "true" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "rvl" "false" $binlog + +Remove-Item -Recurse "output/F#" From 065659cf753ffa2c0f7ab549c11d3230ff142217 Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Tue, 7 May 2024 12:05:29 +0200 Subject: [PATCH 07/10] fix formatting and duplicate PackageReference --- .../csharp/xplat/AvaloniaTest/AvaloniaTest.csproj | 10 +++++----- .../fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj | 13 ++++++------- 2 files changed, 11 insertions(+), 12 deletions(-) diff --git a/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj b/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj index d190c762..6a42d303 100644 --- a/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj +++ b/templates/csharp/xplat/AvaloniaTest/AvaloniaTest.csproj @@ -18,10 +18,10 @@ - - - - - + + + + + diff --git a/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj b/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj index 2e62cb6a..1e86966f 100644 --- a/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj +++ b/templates/fsharp/xplat/AvaloniaTest/AvaloniaTest.fsproj @@ -26,14 +26,13 @@ - - + - - - - - + + + + + From 2e2cc3b296f813c262466dec6c5b1b1487b31f72 Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Tue, 7 May 2024 12:06:14 +0200 Subject: [PATCH 08/10] enable verbose output of exact command executed --- tests/build-test.ps1 | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tests/build-test.ps1 b/tests/build-test.ps1 index 8ab803e2..0106d2b3 100644 --- a/tests/build-test.ps1 +++ b/tests/build-test.ps1 @@ -1,3 +1,7 @@ +# Enable common parameters e.g. -Verbose +[CmdletBinding()] +param() + Set-StrictMode -Version latest $ErrorActionPreference = "Stop" @@ -18,7 +22,13 @@ function Exec [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ("Error executing command {0}" -f $cmd) ) - & $cmd + + # Convert the ScriptBlock to a string and expand the variables + $expandedCmdString = $ExecutionContext.InvokeCommand.ExpandString($cmd.ToString()) + Write-Verbose "Executing command: $expandedCmdString" + + Invoke-Command -ScriptBlock $cmd + if ($lastexitcode -ne 0) { throw ("Exec: " + $errorMessage) } From ff9e137aea23d471b074fc75b9c3b891fa2d6133 Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Tue, 7 May 2024 12:06:55 +0200 Subject: [PATCH 09/10] ignore errors when deleting output directories --- tests/build-test.ps1 | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/build-test.ps1 b/tests/build-test.ps1 index 0106d2b3..9fb61a07 100644 --- a/tests/build-test.ps1 +++ b/tests/build-test.ps1 @@ -102,6 +102,7 @@ if (Test-Path "output") { Remove-Item -Recurse output } +# Use same log file for all executions $binlog = [IO.Path]::GetFullPath([IO.Path]::Combine($pwd, "..", "binlog", "test.binlog")) Create-And-Build "avalonia.app" "AvaloniaApp" "C#" "f" "net8.0" $binlog @@ -130,7 +131,8 @@ Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "cb" "false" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "rvl" "true" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "C#" "rvl" "false" $binlog -Remove-Item -Recurse "output/C#" +# Ignore errors when files are still used by another process +Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "output/C#" Create-And-Build "avalonia.app" "AvaloniaApp" "F#" "f" "net8.0" $binlog Create-And-Build "avalonia.app" "AvaloniaApp" "F#" "av" "11.0.10" $binlog @@ -157,4 +159,5 @@ Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "cb" "false" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "rvl" "true" $binlog Create-And-Build "avalonia.xplat" "AvaloniaXplat" "F#" "rvl" "false" $binlog -Remove-Item -Recurse "output/F#" +# Ignore errors when files are still used by another process +Remove-Item -Recurse -Force -ErrorAction SilentlyContinue "output/F#" From e847772278ea3f93e9ff63a1835d941636489444 Mon Sep 17 00:00:00 2001 From: FroggieFrog Date: Tue, 7 May 2024 12:08:35 +0200 Subject: [PATCH 10/10] clear outputs from possible previous runs --- tests/build-test.ps1 | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tests/build-test.ps1 b/tests/build-test.ps1 index 9fb61a07..534d2161 100644 --- a/tests/build-test.ps1 +++ b/tests/build-test.ps1 @@ -21,7 +21,7 @@ function Exec param( [Parameter(Position=0,Mandatory=1)][scriptblock]$cmd, [Parameter(Position=1,Mandatory=0)][string]$errorMessage = ("Error executing command {0}" -f $cmd) - ) + ) # Convert the ScriptBlock to a string and expand the variables $expandedCmdString = $ExecutionContext.InvokeCommand.ExpandString($cmd.ToString()) @@ -90,7 +90,7 @@ function Create-And-Build { # Remove dots and - from folderName because in sln it will cause errors when building project $folderName = $folderName -replace "[.-]" - + # Create the project Exec { dotnet new $template -o output/$lang/$folderName -$parameterName $value -lang $lang } @@ -98,8 +98,18 @@ function Create-And-Build { Exec { dotnet build output/$lang/$folderName -bl:$bl } } -if (Test-Path "output") { - Remove-Item -Recurse output +# Clear file system from possible previous runs +Write-Output "Clearing outputs from possible previous runs" +if (Test-Path "output" -ErrorAction SilentlyContinue) { + Remove-Item -Recurse -Force "output" +} +$outDir = [IO.Path]::GetFullPath([IO.Path]::Combine($pwd, "..", "output")) +if (Test-Path $outDir -ErrorAction SilentlyContinue) { + Remove-Item -Recurse -Force $outDir +} +$binLogDir = [IO.Path]::GetFullPath([IO.Path]::Combine($pwd, "..", "binlog")) +if (Test-Path $binLogDir -ErrorAction SilentlyContinue) { + Remove-Item -Recurse -Force $binLogDir } # Use same log file for all executions