Skip to content

Add the feature flag that allows users to opt out automatic UTF8 console encoding#51261

Merged
GangWang01 merged 4 commits intodotnet:mainfrom
GangWang01:use-default-encoding
Jan 9, 2026
Merged

Add the feature flag that allows users to opt out automatic UTF8 console encoding#51261
GangWang01 merged 4 commits intodotnet:mainfrom
GangWang01:use-default-encoding

Conversation

@GangWang01
Copy link
Member

As part of the fix dotnet/msbuild#12637

To fix dotnet build, it needs to apply the feature flag in dotnet too.

Here is the comparison before/after the fix.
image

Copilot AI review requested due to automatic review settings October 15, 2025 03:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds support for a feature flag CONSOLE_USE_DEFAULT_ENCODING that allows users to opt out of automatic UTF8 console encoding. This change is part of a fix to address issues with dotnet build and console encoding behavior.

  • Adds environment variable check before setting UTF8 encoding in the main dotnet CLI entry point
  • Adds the same environment variable check in the UI language override setup
  • Provides users control over console encoding behavior through the CONSOLE_USE_DEFAULT_ENCODING flag

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/Cli/dotnet/Program.cs Wraps UTF8 console encoding setup with feature flag check
src/Cli/Microsoft.DotNet.Cli.Utils/UILanguageOverride.cs Wraps console encoding logic in Setup method with feature flag check

@KalleOlaviNiemitalo
Copy link
Contributor

I don't like the CONSOLE_USE_DEFAULT_ENCODING name because

  • shouldn't it start with DOTNET_
  • it doesn't actually reset the console to the default encoding; instead it preserves the current encoding, which may have been set by an earlier process

@GangWang01
Copy link
Member Author

@baronfel can you please take a look?

@YuliiaKovalova YuliiaKovalova dismissed baronfel’s stale review January 7, 2026 14:57

reset review since the comments were resolved

YuliiaKovalova added a commit to dotnet/msbuild that referenced this pull request Jan 7, 2026
…ole encoding (#12637)

Fixes #11850

### Context
In non-English system especially like Japanese/Chinese, when redirecting
the console output which is in UTF8 encoding to the pipe, the output is
garbled. There is no way to detect the encoding of the destination. So
add the feature flag that allows users to opt out automatic UTF8 console
encoding.

### Changes Made
Opt out automatic UTF8 console encoding by setting the environment
variable `CONSOLE_USE_DEFAULT_ENCODING` to `1`.

### Testing
Manually tested. 
For msbuild.exe
<img width="1108" height="306" alt="image"
src="https://github.com/user-attachments/assets/9f03eeef-dd72-4df4-9747-5f8a23796800"
/>

For `dotnet build`, it requires the change in SDK
dotnet/sdk#51261.

### Notes

---------

Co-authored-by: YuliiaKovalova <[email protected]>
@GangWang01 GangWang01 merged commit 01fec82 into dotnet:main Jan 9, 2026
26 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants