Skip to content

Commit

Permalink
Merge pull request #18958 from unoplatform/dev/dr/logAddInDisocvery
Browse files Browse the repository at this point in the history
fix: Fix logging of add-in discovery
  • Loading branch information
jeromelaban authored Nov 29, 2024
2 parents 47a571b + 738ff21 commit bdf10e2
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 4 deletions.
33 changes: 29 additions & 4 deletions src/Uno.UI.RemoteControl.Host/Extensibility/AddIns.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,54 @@ public class AddIns
public static IImmutableList<string> Discover(string solutionFile)
{
var tmp = Path.GetTempFileName();
var result = ProcessHelper.RunProcess("dotnet", $"build \"{solutionFile}\" --target:UnoDumpTargetFrameworks \"-p:UnoDumpTargetFrameworksTargetFile={tmp}\" --verbosity quiet");
var command = $"build \"{solutionFile}\" --target:UnoDumpTargetFrameworks \"-p:UnoDumpTargetFrameworksTargetFile={tmp}\" --verbosity quiet";
var result = ProcessHelper.RunProcess("dotnet", command);
var targetFrameworks = Read(tmp);

if (targetFrameworks.IsEmpty)
{
if (_log.IsEnabled(LogLevel.Warning))
{
_log.Log(LogLevel.Warning, new Exception(result.error), $"Failed to get target frameworks of solution '{solutionFile}' (cf. inner exception for details).");
var msg = $"Failed to get target frameworks of solution '{solutionFile}'. "
+ "This usually indicates that the solution is in an invalid state (e.g. a referenced project is missing on disk). "
+ $"Please fix and restart your IDE (command used: `dotnet {command}`).";
if (result.error is { Length: > 0 })
{
_log.Log(LogLevel.Warning, new Exception(result.error), msg + " (cf. inner exception for more details.)");
}
else
{
_log.Log(LogLevel.Warning, msg);
}
}

return ImmutableArray<string>.Empty;
}

if (_log.IsEnabled(LogLevel.Debug))
{
_log.Log(LogLevel.Debug, $"Found target frameworks for solution '{solutionFile}': {string.Join(", ", targetFrameworks)}.");
}


foreach (var targetFramework in targetFrameworks)
{
tmp = Path.GetTempFileName();
result = ProcessHelper.RunProcess("dotnet", $"build \"{solutionFile}\" --target:UnoDumpRemoteControlAddIns \"-p:UnoDumpRemoteControlAddInsTargetFile={tmp}\" --verbosity quiet --framework \"{targetFramework}\" -nowarn:MSB4057");
command = $"build \"{solutionFile}\" --target:UnoDumpRemoteControlAddIns \"-p:UnoDumpRemoteControlAddInsTargetFile={tmp}\" --verbosity quiet --framework \"{targetFramework}\" -nowarn:MSB4057";
result = ProcessHelper.RunProcess("dotnet", command);
if (!string.IsNullOrWhiteSpace(result.error))
{
if (_log.IsEnabled(LogLevel.Warning))
{
_log.Log(LogLevel.Warning, new Exception(result.error), $"Failed to get add-ins for solution '{solutionFile}' for tfm {targetFramework} (cf. inner exception for details).");
var msg = $"Failed to get add-ins for solution '{solutionFile}' for tfm {targetFramework} (command used: `dotnet {command}`).";
if (result.error is { Length: > 0 })
{
_log.Log(LogLevel.Warning, new Exception(result.error), msg + " (cf. inner exception for more details.)");
}
else
{
_log.Log(LogLevel.Warning, msg);
}
}

continue;
Expand Down
13 changes: 13 additions & 0 deletions src/Uno.UI.RemoteControl.Host/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Diagnostics;
using System.ComponentModel;
using System.Threading.Tasks;
using Uno.Extensions;
using Uno.UI.RemoteControl.Host.Extensibility;
using Uno.UI.RemoteControl.Host.IdeChannel;
using Uno.UI.RemoteControl.Services;
Expand Down Expand Up @@ -61,6 +62,11 @@ static async Task Main(string[] args)
throw new ArgumentException($"The httpPort parameter is required.");
}

const LogLevel logLevel = LogLevel.Debug;

// During init, we dump the logs to the console, until the logger is set up
Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory = LoggerFactory.Create(builder => builder.SetMinimumLevel(logLevel).AddConsole());

var builder = new WebHostBuilder()
.UseSetting("UseIISIntegration", false.ToString())
.UseKestrel()
Expand All @@ -86,9 +92,16 @@ static async Task Main(string[] args)
// For backward compatibility, we allow to not have a solution file specified.
builder.ConfigureAddIns(solution);
}
else
{
typeof(Program).Log().Log(LogLevel.Warning, "No solution file specified, add-ins will not be loaded which means that you won't be able to use any of the uno-studio features. Usually this indicates that your version of uno's IDE extension is too old.");
}

var host = builder.Build();

// Once the app has started, we use the logger from the host
Uno.Extensions.LogExtensionPoint.AmbientLoggerFactory = host.Services.GetRequiredService<ILoggerFactory>();

host.Services.GetService<IIdeChannel>();

using var parentObserver = ParentProcessObserver.Observe(host, parentPID);
Expand Down

0 comments on commit bdf10e2

Please sign in to comment.