-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Add the feature flag that allows users to opt out automatic UTF8 console encoding #12637
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this 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 a feature flag to allow users to opt out of MSBuild's automatic UTF-8 console encoding. The change addresses garbled output issues in non-English systems (Japanese/Chinese) when redirecting console output to pipes.
- Introduces environment variable
CONSOLE_USE_DEFAULT_ENCODINGto control UTF-8 encoding behavior - Wraps existing UTF-8 encoding logic in a conditional check
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It feels like we need an additional check here - if the CurrentUICulture is in a locale that doesn't support UTF8 then we should just not do automatic UTF8 encoding by default. The default behaviors/usage of the tool should just work for all users, regardless of locale.
| /// <summary> | ||
| /// Make Console use default encoding in the system. It opts out automatic console encoding UTF-8. | ||
| /// </summary> | ||
| public readonly bool ConsoleUseDefaultEncoding = Environment.GetEnvironmentVariable("CONSOLE_USE_DEFAULT_ENCODING") == "1"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any MSBuild-specific environment variable needs to start with an MSBUILD prefix.
@baronfel any reference of determining if the CurrentUICulture is in a locale that doesn't support UTF8? Currently, Lines 1938 to 1941 in 9373f72
For the issue, actually Windows with the locale ja-jp supports UTF8. MSbuild output encoded in UTF8 is displayed well. But after the output is piped with |
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_ENCODINGto1.Testing
Manually tested.

For msbuild.exe
For
dotnet build, it requires the change in SDK dotnet/sdk#51261.Notes