diff --git a/src/Uno.Sdk/targets/Uno.Build.targets b/src/Uno.Sdk/targets/Uno.Build.targets index b91ffbc698e9..cea2c1957747 100644 --- a/src/Uno.Sdk/targets/Uno.Build.targets +++ b/src/Uno.Sdk/targets/Uno.Build.targets @@ -148,6 +148,12 @@ It is useful to determine all target frameworks used by all projects of a solution. --> + Discover(string solutionFile) { - // Note: With .net 9 we need to specify --verbosity detailed to get messages with High importance. - var result = ProcessHelper.RunProcess("dotnet", $"build \"{solutionFile}\" --target:UnoDumpTargetFrameworks --verbosity detailed"); - var targetFrameworks = GetConfigurationValue(result.output ?? "", "TargetFrameworks") - .SelectMany(tfms => tfms.Split(['\r', '\n', ';', ','], StringSplitOptions.RemoveEmptyEntries)) - .Select(tfm => tfm.Trim()) - .Where(tfm => tfm is { Length: > 0 }) - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToImmutableList(); + var tmp = Path.GetTempFileName(); + var result = ProcessHelper.RunProcess("dotnet", $"build \"{solutionFile}\" --target:UnoDumpTargetFrameworks \"-p:UnoDumpTargetFrameworksTargetFile={tmp}\" --verbosity quiet"); + var targetFrameworks = Read(tmp); if (targetFrameworks.IsEmpty) { @@ -37,7 +33,8 @@ public static IImmutableList Discover(string solutionFile) foreach (var targetFramework in targetFrameworks) { - result = ProcessHelper.RunProcess("dotnet", $"build \"{solutionFile}\" --target:UnoDumpRemoteControlAddIns --verbosity detailed --framework \"{targetFramework}\" -nowarn:MSB4057"); + tmp = Path.GetTempFileName(); + result = ProcessHelper.RunProcess("dotnet", $"build \"{solutionFile}\" --target:UnoDumpRemoteControlAddIns \"-p:UnoDumpRemoteControlAddInsTargetFile={tmp}\" --verbosity quiet --framework \"{targetFramework}\" -nowarn:MSB4057"); if (!string.IsNullOrWhiteSpace(result.error)) { if (_log.IsEnabled(LogLevel.Warning)) @@ -48,13 +45,7 @@ public static IImmutableList Discover(string solutionFile) continue; } - var addIns = GetConfigurationValue(result.output, "RemoteControlAddIns") - .SelectMany(tfms => tfms.Split(['\r', '\n', ';', ','], StringSplitOptions.RemoveEmptyEntries)) - .Select(tfm => tfm.Trim()) - .Where(tfm => tfm is { Length: > 0 }) - .Distinct(StringComparer.OrdinalIgnoreCase) - .ToImmutableList(); - + var addIns = Read(tmp); if (!addIns.IsEmpty) { return addIns; @@ -69,9 +60,27 @@ public static IImmutableList Discover(string solutionFile) return ImmutableArray.Empty; } - private static IEnumerable GetConfigurationValue(string msbuildResult, string nodeName) - => Regex - .Matches(msbuildResult, $"<{nodeName}>(?[^\\<\\>]*)", RegexOptions.Singleline) - .Where(match => match.Success) - .Select(match => match.Groups["value"].Value); + private static ImmutableList Read(string file) + { + var values = ImmutableList.Empty; + try + { + values = File + .ReadAllLines(file, Encoding.Unicode) + .SelectMany(line => line.Split(['\r', '\n', ';', ','], StringSplitOptions.RemoveEmptyEntries)) + .Select(value => value.Trim()) + .Where(value => value is { Length: > 0 }) + .Distinct(StringComparer.OrdinalIgnoreCase) + .ToImmutableList(); + } + catch { } + + try + { + File.Delete(file); + } + catch { } + + return values; + } } diff --git a/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets b/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets index f5f251763e74..2a33b6875fa8 100644 --- a/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets +++ b/src/Uno.UI.RemoteControl/buildTransitive/Uno.WinUI.DevServer.targets @@ -33,6 +33,12 @@ +