Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/MSBuild/LiveLogger/Terminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace Microsoft.Build.Logging.LiveLogger;
internal sealed class Terminal : ITerminal
{
/// <summary>
/// The encoding read from <see cref="Console.OutputEncoding"/> when the terminal is instantiated.
/// The encoding read from <see cref="Console.OutputEncoding"/> when the terminal is constructed.
/// </summary>
private readonly Encoding _originalOutputEncoding;

Expand Down Expand Up @@ -67,6 +67,10 @@ public Terminal()
_originalOutputEncoding = Console.OutputEncoding;
Console.OutputEncoding = Encoding.UTF8;

// Capture the TextWriter AFTER setting the encoding, because setting
// the encoding creates a new TextWriter in the Console class, but it's
// possible to hang on to the old one (with the wrong encoding) and emit
// garbage, as in https://github.com/dotnet/msbuild/issues/9030.
Output = Console.Out;
}

Expand Down