From 785b58b9635125fe969a74b4b9b3a40e0641186d Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Feb 2025 12:24:45 -0500 Subject: [PATCH 1/3] fix: Pack add-ins discovery tragets with the dev-server to be able to run them no matter the SDK sued by the project (cherry picked from commit 36a0d9b10749e8a6f3319a7dd0fa6151d189b11e) # Conflicts: # src/Uno.Sdk/targets/Uno.Build.targets --- src/Uno.Sdk/targets/Uno.Build.targets | 4 +++ .../DevServer.Custom.Targets | 25 +++++++++++++++++++ .../Extensibility/AddIns.cs | 12 +++++++-- .../Helpers/ProcessHelper.cs | 9 +++++++ .../Uno.WinUI.DevServer.targets | 10 -------- 5 files changed, 48 insertions(+), 12 deletions(-) create mode 100644 src/Uno.UI.RemoteControl.Host/DevServer.Custom.Targets diff --git a/src/Uno.Sdk/targets/Uno.Build.targets b/src/Uno.Sdk/targets/Uno.Build.targets index c3a0b1d3b320..694d9bfc9925 100644 --- a/src/Uno.Sdk/targets/Uno.Build.targets +++ b/src/Uno.Sdk/targets/Uno.Build.targets @@ -142,6 +142,7 @@ +<<<<<<< HEAD +======= + +>>>>>>> 36a0d9b107 (fix: Pack add-ins discovery tragets with the dev-server to be able to run them no matter the SDK sued by the project) diff --git a/src/Uno.UI.RemoteControl.Host/DevServer.Custom.Targets b/src/Uno.UI.RemoteControl.Host/DevServer.Custom.Targets new file mode 100644 index 000000000000..450e6023a21d --- /dev/null +++ b/src/Uno.UI.RemoteControl.Host/DevServer.Custom.Targets @@ -0,0 +1,25 @@ + + + + + + + + + + + + diff --git a/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs b/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs index bfb27344276c..268c433d083d 100644 --- a/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs +++ b/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs @@ -3,6 +3,7 @@ using System.Diagnostics; using System.IO; using System.Linq; +using System.Reflection; using System.Text; using Microsoft.Extensions.Logging; using Uno.Extensions; @@ -16,9 +17,13 @@ public class AddIns public static IImmutableList Discover(string solutionFile) { + // Note: We include the targets "on the fly" so if a project uses Microsoft.NET.Sdk instead of Uno.Sdk, we will still have the targets defined. + var targetsFile = Path.Combine(Assembly.GetExecutingAssembly().Location, "DevServer.Custom.Targets"); + var tmp = Path.GetTempFileName(); var wd = Path.GetDirectoryName(solutionFile); - var command = $"build \"{solutionFile}\" -t:UnoDumpTargetFrameworks \"-p:UnoDumpTargetFrameworksTargetFile={tmp}\" --verbosity quiet"; + string DumpTFM(string v) => $"build \"{solutionFile}\" -t:UnoDumpTargetFrameworks \"-p:UnoDumpTargetFrameworksTargetFile={tmp}\" \"-p:CustomBeforeMicrosoftCSharpTargets={targetsFile}\" --verbosity {v}"; + var command = DumpTFM("quiet"); var result = ProcessHelper.RunProcess("dotnet", command, wd); var targetFrameworks = Read(tmp); @@ -35,7 +40,10 @@ public static IImmutableList Discover(string solutionFile) } else { + result = ProcessHelper.RunProcess("dotnet", DumpTFM("diagnostics"), wd); + _log.Log(LogLevel.Warning, msg); + _log.Log(LogLevel.Debug, result.output); } } @@ -51,7 +59,7 @@ public static IImmutableList Discover(string solutionFile) foreach (var targetFramework in targetFrameworks) { tmp = Path.GetTempFileName(); - command = $"build \"{solutionFile}\" -t:UnoDumpRemoteControlAddIns \"-p:UnoDumpRemoteControlAddInsTargetFile={tmp}\" --verbosity quiet --framework \"{targetFramework}\" -nowarn:MSB4057"; + command = $"build \"{solutionFile}\" -t:UnoDumpRemoteControlAddIns \"-p:UnoDumpRemoteControlAddInsTargetFile={tmp}\" \"-p:CustomBeforeMicrosoftCSharpTargets={targetsFile}\" --verbosity quiet --framework \"{targetFramework}\" -nowarn:MSB4057"; result = ProcessHelper.RunProcess("dotnet", command, wd); if (!string.IsNullOrWhiteSpace(result.error)) { diff --git a/src/Uno.UI.RemoteControl.Server.Processors/Helpers/ProcessHelper.cs b/src/Uno.UI.RemoteControl.Server.Processors/Helpers/ProcessHelper.cs index 40ff4c45d8c0..6a1eacbf0d6e 100644 --- a/src/Uno.UI.RemoteControl.Server.Processors/Helpers/ProcessHelper.cs +++ b/src/Uno.UI.RemoteControl.Server.Processors/Helpers/ProcessHelper.cs @@ -6,11 +6,15 @@ using System.IO; using System.Runtime.InteropServices; using System.Text; +using Microsoft.Extensions.Logging; +using Uno.Extensions; namespace Uno.UI.RemoteControl.Helpers { internal class ProcessHelper { + private static readonly ILogger _log = typeof(ProcessHelper).Log(); + public static (int exitCode, string output, string error) RunProcess(string executable, string parameters, string? workingDirectory = null) { if (!OperatingSystem.IsWindows() @@ -19,6 +23,11 @@ public static (int exitCode, string output, string error) RunProcess(string exec executable = Path.GetFileNameWithoutExtension(executable); } + if (_log.IsEnabled(LogLevel.Trace)) + { + _log.LogTrace($"Executing '{executable} {parameters}' in '{workingDirectory ?? Environment.CurrentDirectory}'"); + } + var p = new Process { StartInfo = diff --git a/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets b/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets index 9f2fe923b1de..c3b3eede2194 100644 --- a/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets +++ b/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets @@ -31,16 +31,6 @@ - - - - - From 7bf53c254bac8edfcddf894cc1854d78c0778296 Mon Sep 17 00:00:00 2001 From: David Date: Thu, 6 Feb 2025 14:46:23 -0500 Subject: [PATCH 2/3] fix: Fix invalid config when using Uno.SDK (cherry picked from commit f980d054140399184ccadf1c4097fa703b61e8e0) # Conflicts: # src/Uno.Sdk/targets/Uno.Build.targets --- src/Uno.Sdk/targets/Uno.Build.targets | 6 +++++ .../DevServer.Custom.Targets | 20 ++--------------- .../Extensibility/AddIns.cs | 4 ++-- .../Uno.UI.RemoteControl.Host.csproj | 22 ++++++++++++------- .../Uno.WinUI.DevServer.targets | 10 +++++++++ 5 files changed, 34 insertions(+), 28 deletions(-) diff --git a/src/Uno.Sdk/targets/Uno.Build.targets b/src/Uno.Sdk/targets/Uno.Build.targets index 694d9bfc9925..49756f66177d 100644 --- a/src/Uno.Sdk/targets/Uno.Build.targets +++ b/src/Uno.Sdk/targets/Uno.Build.targets @@ -142,6 +142,7 @@ +<<<<<<< HEAD <<<<<<< HEAD - - + - - + diff --git a/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs b/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs index 268c433d083d..1dedf795d030 100644 --- a/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs +++ b/src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs @@ -18,7 +18,7 @@ public class AddIns public static IImmutableList Discover(string solutionFile) { // Note: We include the targets "on the fly" so if a project uses Microsoft.NET.Sdk instead of Uno.Sdk, we will still have the targets defined. - var targetsFile = Path.Combine(Assembly.GetExecutingAssembly().Location, "DevServer.Custom.Targets"); + var targetsFile = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location)!, "DevServer.Custom.Targets"); var tmp = Path.GetTempFileName(); var wd = Path.GetDirectoryName(solutionFile); @@ -40,7 +40,7 @@ public static IImmutableList Discover(string solutionFile) } else { - result = ProcessHelper.RunProcess("dotnet", DumpTFM("diagnostics"), wd); + result = ProcessHelper.RunProcess("dotnet", DumpTFM("diagnostic"), wd); _log.Log(LogLevel.Warning, msg); _log.Log(LogLevel.Debug, result.output); diff --git a/src/Uno.UI.RemoteControl.Host/Uno.UI.RemoteControl.Host.csproj b/src/Uno.UI.RemoteControl.Host/Uno.UI.RemoteControl.Host.csproj index 8fbf3abaa219..18f378313c54 100644 --- a/src/Uno.UI.RemoteControl.Host/Uno.UI.RemoteControl.Host.csproj +++ b/src/Uno.UI.RemoteControl.Host/Uno.UI.RemoteControl.Host.csproj @@ -49,13 +49,13 @@ - - + + Never @@ -67,7 +67,13 @@ Always global.json - + + + + + Always + + diff --git a/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets b/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets index c3b3eede2194..9f2fe923b1de 100644 --- a/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets +++ b/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets @@ -31,6 +31,16 @@ + + + + + From df82d5fd64992b1fe96d21d77cac14688b7a2714 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 7 Feb 2025 09:20:08 -0500 Subject: [PATCH 3/3] fix: Fix merge conflict --- src/Uno.Sdk/targets/Uno.Build.targets | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/src/Uno.Sdk/targets/Uno.Build.targets b/src/Uno.Sdk/targets/Uno.Build.targets index 49756f66177d..c3a0b1d3b320 100644 --- a/src/Uno.Sdk/targets/Uno.Build.targets +++ b/src/Uno.Sdk/targets/Uno.Build.targets @@ -142,8 +142,6 @@ -<<<<<<< HEAD -<<<<<<< HEAD