-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Add the feature flag that allows users to opt out automatic UTF8 console encoding #51261
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 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_ENCODINGflag
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 |
|
|
||
| // Setting output encoding is not available on those platforms | ||
| if (UILanguageOverride.OperatingSystemSupportsUtf8()) | ||
| if (Environment.GetEnvironmentVariable("CONSOLE_USE_DEFAULT_ENCODING") != "1") |
Copilot
AI
Oct 15, 2025
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.
Consider extracting the environment variable name and value into named constants to avoid magic strings and improve maintainability. This would also ensure consistency across the codebase where this same check is performed.
|
|
||
| if ( | ||
| !CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("en", StringComparison.InvariantCultureIgnoreCase) && | ||
| if (Environment.GetEnvironmentVariable("CONSOLE_USE_DEFAULT_ENCODING") != "1") |
Copilot
AI
Oct 15, 2025
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.
Consider extracting the environment variable name and value into named constants to avoid magic strings and improve maintainability. This duplicates the same magic strings used in Program.cs.
|
I don't like the
|
|
@baronfel can you please take a look? |
|
|
||
| // Setting output encoding is not available on those platforms | ||
| if (UILanguageOverride.OperatingSystemSupportsUtf8()) | ||
| if (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 env variables that are important to the dotnet CLI need a DOTNET_CLI_ prefix, and then we'd need to 'transform' them to the MSBuild-friendly version before we call out to MSBuild in the MSBuildforwardingApp.cs logic.
|
|
||
| if ( | ||
| !CultureInfo.CurrentUICulture.TwoLetterISOLanguageName.Equals("en", StringComparison.InvariantCultureIgnoreCase) && | ||
| if (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.
Similar to my comment on the MSBuild side - this feels wrong. If we know the locale that we're using, and we know that the locale doesn't support UTF8 output for some reason, then we shouldn't do the UTF8 encoding change.
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.
