From bc0be29a0b4af25d480c4685510505bafe432d4b Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Mon, 7 Oct 2024 16:21:50 -0700
Subject: [PATCH 1/8] Create Working BuildTask
---
samples/CommunityToolkit.Maui.Sample.sln | 6 ++++++
.../CommunityToolkit.Maui.BuildTasks.csproj | 11 +++++++++++
.../VerifyMauiWorkloadVersionTask.net.cs | 10 ++++++++++
.../CommunityToolkit.Maui.Core.csproj | 6 ++++++
4 files changed, 33 insertions(+)
create mode 100644 src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj
create mode 100644 src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs
diff --git a/samples/CommunityToolkit.Maui.Sample.sln b/samples/CommunityToolkit.Maui.Sample.sln
index 94bec1c258..97f9624344 100644
--- a/samples/CommunityToolkit.Maui.Sample.sln
+++ b/samples/CommunityToolkit.Maui.Sample.sln
@@ -53,6 +53,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Benchmarks", "Benchmarks",
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "..\src\CommunityToolkit.Maui.Analyzers.Benchmarks\CommunityToolkit.Maui.Analyzers.Benchmarks.csproj", "{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Maui.BuildTasks", "..\src\CommunityToolkit.Maui.BuildTasks\CommunityToolkit.Maui.BuildTasks.csproj", "{9F3FA434-F075-46E9-852F-098214966A57}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -131,6 +133,10 @@ Global
{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}.Debug|Any CPU.Build.0 = Debug|Any CPU
{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}.Release|Any CPU.ActiveCfg = Release|Any CPU
{B80F59B7-276C-4A55-A8DD-54587C8BC3D2}.Release|Any CPU.Build.0 = Release|Any CPU
+ {9F3FA434-F075-46E9-852F-098214966A57}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {9F3FA434-F075-46E9-852F-098214966A57}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {9F3FA434-F075-46E9-852F-098214966A57}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {9F3FA434-F075-46E9-852F-098214966A57}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
diff --git a/src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj b/src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj
new file mode 100644
index 0000000000..bc21b735e1
--- /dev/null
+++ b/src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj
@@ -0,0 +1,11 @@
+
+
+
+ $(NetVersion)
+
+
+
+
+
+
+
diff --git a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs
new file mode 100644
index 0000000000..787a181e5b
--- /dev/null
+++ b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs
@@ -0,0 +1,10 @@
+namespace CommunityToolkit.Maui.BuildTasks;
+
+///
+/// An MSBuild task to ensure that developers have the required version of .NET MAUI Workload installed
+///
+public class VerifyMauiWorkloadVersionTask : Microsoft.Build.Utilities.Task
+{
+ ///
+ public override bool Execute() => false;
+}
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj b/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
index a85cb7a014..62f023c0f9 100644
--- a/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
+++ b/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
@@ -44,6 +44,12 @@
Debug;Release
+
+
+
+
+
+
From e1d8477f3bcd22519cd4e133ac7c347d129c59e1 Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Mon, 7 Oct 2024 17:23:50 -0700
Subject: [PATCH 2/8] Finish VerifyMauiWorkloadVersionTask
---
Directory.Build.props | 1 +
.../VerifyMauiWorkloadVersionTask.net.cs | 10 ---
.../VerifyMauiWorkloadVersionTask.shared.cs | 83 +++++++++++++++++++
.../CommunityToolkit.Maui.Core.csproj | 4 +-
4 files changed, 86 insertions(+), 12 deletions(-)
delete mode 100644 src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs
create mode 100644 src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
diff --git a/Directory.Build.props b/Directory.Build.props
index b7803c1c6f..3873d13b05 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -3,6 +3,7 @@
net8.0
8.0.71
+ 8.0.402.1
latest
enable
enable
diff --git a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs
deleted file mode 100644
index 787a181e5b..0000000000
--- a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.net.cs
+++ /dev/null
@@ -1,10 +0,0 @@
-namespace CommunityToolkit.Maui.BuildTasks;
-
-///
-/// An MSBuild task to ensure that developers have the required version of .NET MAUI Workload installed
-///
-public class VerifyMauiWorkloadVersionTask : Microsoft.Build.Utilities.Task
-{
- ///
- public override bool Execute() => false;
-}
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
new file mode 100644
index 0000000000..43d80e2b56
--- /dev/null
+++ b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
@@ -0,0 +1,83 @@
+using System.Diagnostics;
+using System.Text.RegularExpressions;
+using Microsoft.Build.Framework;
+
+namespace CommunityToolkit.Maui.BuildTasks;
+
+public partial class VerifyMauiWorkloadVersionTask : Microsoft.Build.Utilities.Task
+{
+ static readonly ProcessStartInfo processStartInfo = new()
+ {
+ FileName = "dotnet",
+ Arguments = "workload list",
+ UseShellExecute = false,
+ RedirectStandardOutput = true,
+ CreateNoWindow = true,
+ WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory
+ };
+
+ [Required]
+ public string MinimumRequiredMauiVersion { get; set; } = string.Empty;
+
+ public override bool Execute()
+ {
+ try
+ {
+ var dotnetOutput = GetDotnetWorkloadOutput();
+ var installedMauiWorkloadVersion = ExtractMauiVersion(dotnetOutput);
+
+ if (string.IsNullOrEmpty(installedMauiWorkloadVersion))
+ {
+ Log.LogError($"No MAUI workload installed/n{GenerateTroubleshootingText(MinimumRequiredMauiVersion)}");
+ return false;
+ }
+
+ var currentVersion = Version.Parse(installedMauiWorkloadVersion);
+ var minimumRequiredVersion = Version.Parse(MinimumRequiredMauiVersion);
+
+ if (currentVersion < minimumRequiredVersion)
+ {
+ Log.LogError($"The installed MAUI workload version, {installedMauiWorkloadVersion}, does not meet the minimum version required by the .NET MAUI Community Toolkit: {MinimumRequiredMauiVersion}./n{GenerateTroubleshootingText(MinimumRequiredMauiVersion)}");
+ return false;
+ }
+
+ Log.LogMessage(MessageImportance.Normal, $"MAUI workload version {installedMauiWorkloadVersion} satisfies the required version {MinimumRequiredMauiVersion}.");
+
+ return true;
+ }
+ catch (Exception ex)
+ {
+ Log.LogErrorFromException(ex);
+ return false;
+ }
+ }
+
+ static string GetDotnetWorkloadOutput()
+ {
+ using var process = new Process();
+ process.StartInfo = processStartInfo;
+
+ process.Start();
+ var output = process.StandardOutput.ReadToEnd();
+ process.WaitForExit();
+
+ return output;
+ }
+
+ static string? ExtractMauiVersion(string dotnetOutput)
+ {
+ var match = VerifyWorkloadVersion().Match(dotnetOutput);
+
+ return match.Success ? match.Groups[0].Value : null;
+ }
+
+ static string GenerateTroubleshootingText(in string minimumMauiVersion) =>
+ $"""
+ Follow these steps to install the required .NET MAUI workload:
+ 1. Using your web browser, download the latest stable release of the .NET SDK and install it on your machine: https://dotnet.microsoft.com/download/dotnet
+ 2. After installing the latest version of .NET, using your console, use the command `dotnet workload install maui --version {minimumMauiVersion}` to update to the latest stable version of .NET MAUI \n
+ """;
+
+ [GeneratedRegex(@"(?<=Workload version: )\d+\.\d+\.\d+\.\d+")]
+ private static partial Regex VerifyWorkloadVersion();
+}
\ No newline at end of file
diff --git a/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj b/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
index 62f023c0f9..eb90a355f4 100644
--- a/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
+++ b/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
@@ -46,8 +46,8 @@
-
-
+
+
From 9bcbc6f54b83656b649dd0be8457057a08bf91f4 Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Mon, 7 Oct 2024 17:25:26 -0700
Subject: [PATCH 3/8] Update CommunityToolkit.Maui.sln
---
src/CommunityToolkit.Maui.sln | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/src/CommunityToolkit.Maui.sln b/src/CommunityToolkit.Maui.sln
index a6f1d13c4f..43e8fa3ee0 100644
--- a/src/CommunityToolkit.Maui.sln
+++ b/src/CommunityToolkit.Maui.sln
@@ -45,6 +45,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Maui.Camer
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Maui.Camera", "CommunityToolkit.Maui.Camera\CommunityToolkit.Maui.Camera.csproj", "{9F4B8437-B200-4F96-B71C-4F4B4A517694}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CommunityToolkit.Maui.BuildTasks", "CommunityToolkit.Maui.BuildTasks\CommunityToolkit.Maui.BuildTasks.csproj", "{55170BFE-DEDB-43D1-8351-302E3CC68BA2}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -111,6 +113,10 @@ Global
{9F4B8437-B200-4F96-B71C-4F4B4A517694}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9F4B8437-B200-4F96-B71C-4F4B4A517694}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9F4B8437-B200-4F96-B71C-4F4B4A517694}.Release|Any CPU.Build.0 = Release|Any CPU
+ {55170BFE-DEDB-43D1-8351-302E3CC68BA2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {55170BFE-DEDB-43D1-8351-302E3CC68BA2}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {55170BFE-DEDB-43D1-8351-302E3CC68BA2}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {55170BFE-DEDB-43D1-8351-302E3CC68BA2}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
From 68528f230ca1bbc12673e94b6a2eec526336b730 Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Mon, 7 Oct 2024 21:45:53 -0700
Subject: [PATCH 4/8] Update CommunityToolkit.Maui.BuildTasks.csproj
Co-authored-by: Pedro Jesus
---
.../CommunityToolkit.Maui.BuildTasks.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj b/src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj
index bc21b735e1..7a2e40df52 100644
--- a/src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj
+++ b/src/CommunityToolkit.Maui.BuildTasks/CommunityToolkit.Maui.BuildTasks.csproj
@@ -5,7 +5,7 @@
-
+
From 4b303c9604c682d3a875d3c3ba58cb9b8b18c70e Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Mon, 7 Oct 2024 21:46:17 -0700
Subject: [PATCH 5/8] Update Directory.Build.props
Co-authored-by: Pedro Jesus
---
Directory.Build.props | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Directory.Build.props b/Directory.Build.props
index 3873d13b05..8ae232017c 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -3,7 +3,7 @@
net8.0
8.0.71
- 8.0.402.1
+ <_RequiredMauiWorkloadVersion>8.0.402.1
latest
enable
enable
From 0ad8124a5884ae3bec456400b91be2155c283a67 Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Tue, 8 Oct 2024 13:43:53 -0700
Subject: [PATCH 6/8] Update
src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
---
.../CommunityToolkit.Maui.Core.csproj | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj b/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
index eb90a355f4..520b3233b6 100644
--- a/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
+++ b/src/CommunityToolkit.Maui.Core/CommunityToolkit.Maui.Core.csproj
@@ -47,7 +47,7 @@
-
+
From 77ea6a9c8cf2719cb95050db21a9af35886a16b1 Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Tue, 10 Dec 2024 15:27:28 -0800
Subject: [PATCH 7/8] Update
src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---
.../VerifyMauiWorkloadVersionTask.shared.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
index 43d80e2b56..d7cd8a4a05 100644
--- a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
+++ b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
@@ -28,7 +28,7 @@ public override bool Execute()
if (string.IsNullOrEmpty(installedMauiWorkloadVersion))
{
- Log.LogError($"No MAUI workload installed/n{GenerateTroubleshootingText(MinimumRequiredMauiVersion)}");
+ Log.LogError($"No MAUI workload installed\n{GenerateTroubleshootingText(MinimumRequiredMauiVersion)}");
return false;
}
From 936b52ee0e025c01a5ec1733d54cdfc8c02d64b0 Mon Sep 17 00:00:00 2001
From: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
Date: Tue, 10 Dec 2024 15:27:33 -0800
Subject: [PATCH 8/8] Update
src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
---
.../VerifyMauiWorkloadVersionTask.shared.cs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
index d7cd8a4a05..03dbb27b28 100644
--- a/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
+++ b/src/CommunityToolkit.Maui.BuildTasks/VerifyMauiWorkloadVersionTask.shared.cs
@@ -37,7 +37,7 @@ public override bool Execute()
if (currentVersion < minimumRequiredVersion)
{
- Log.LogError($"The installed MAUI workload version, {installedMauiWorkloadVersion}, does not meet the minimum version required by the .NET MAUI Community Toolkit: {MinimumRequiredMauiVersion}./n{GenerateTroubleshootingText(MinimumRequiredMauiVersion)}");
+ Log.LogError($"The installed MAUI workload version, {installedMauiWorkloadVersion}, does not meet the minimum version required by the .NET MAUI Community Toolkit: {MinimumRequiredMauiVersion}.\n{GenerateTroubleshootingText(MinimumRequiredMauiVersion)}");
return false;
}