Skip to content

Commit 79e5fa6

Browse files
[release/10.0.2xx] [dotnet-watch] avoid PlatformNotSupportedException on various platforms (#52355)
Backport of #52351 to release/10.0.2xx Co-authored-by: Jonathan Peppers <[email protected]>
1 parent 70eb973 commit 79e5fa6

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/BuiltInTools/HotReloadAgent.Host/StartupHook.cs

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ internal sealed class StartupHook
2222
{
2323
private static readonly string? s_standardOutputLogPrefix = Environment.GetEnvironmentVariable(AgentEnvironmentVariables.HotReloadDeltaClientLogMessages);
2424
private static readonly string? s_namedPipeName = Environment.GetEnvironmentVariable(AgentEnvironmentVariables.DotNetWatchHotReloadNamedPipeName);
25+
private static readonly bool s_supportsConsoleColor = !OperatingSystem.IsAndroid()
26+
&& !OperatingSystem.IsIOS()
27+
&& !OperatingSystem.IsTvOS()
28+
&& !OperatingSystem.IsBrowser();
2529

2630
#if NET10_0_OR_GREATER
2731
private static PosixSignalRegistration? s_signalRegistration;
@@ -160,9 +164,17 @@ private static void Log(string message)
160164
var prefix = s_standardOutputLogPrefix;
161165
if (!string.IsNullOrEmpty(prefix))
162166
{
163-
Console.ForegroundColor = ConsoleColor.DarkGray;
167+
if (s_supportsConsoleColor)
168+
{
169+
Console.ForegroundColor = ConsoleColor.DarkGray;
170+
}
171+
164172
Console.Error.WriteLine($"{prefix} {message}");
165-
Console.ResetColor();
173+
174+
if (s_supportsConsoleColor)
175+
{
176+
Console.ResetColor();
177+
}
166178
}
167179
}
168180
}

0 commit comments

Comments
 (0)