Add the feature flag that allows users to opt out automatic UTF8 console encoding#12637
Add the feature flag that allows users to opt out automatic UTF8 console encoding#12637YuliiaKovalova merged 4 commits intodotnet:mainfrom
Conversation
There was a problem hiding this comment.
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
baronfel
left a comment
There was a problem hiding this comment.
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.
@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 |
|
so this is the fault of the pipe? is this a problem that occurs only in Windows cmd, Windows Powershell, or pwsh? |
@baronfel yes, it's the fault of pipe that uses default encoding Shift-JIS of the Japanese Windows system. And the problem only occurs in Windows cmd, Powershell and pwsh. For Linux and MacOS, the default encoding is UTF-8 regardless of the region or language and the problem doesn't occur. |
|
Ok, we can go ahead with this - making sure that the environment variables have the MSBUILD_/DOTNET_ prefixes mentioned above. I would expect the need for this flag to trend downwards over time - modern Windows, powershell, etc are all either moved to UTF-8 by default or are moving that direction (Windows 10/11 have a switch to enable system-wide!). So this is not something that we should expect to support forever. |
the last comment states we can move forward with this pr after making some changes. the changes are in place
Updated [Microsoft.Build](https://github.com/dotnet/msbuild) from 18.3.3 to 18.4.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Build's releases](https://github.com/dotnet/msbuild/releases)._ ## 18.4.0 ## What's Changed * Fix terminal logger quiet mode to show project context for warnings/errors by @Copilot in dotnet/msbuild#12930 * Replace OpenTelemetry with Microsoft.VisualStudio.Telemetry for VS by @YuliiaKovalova in dotnet/msbuild#12843 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13050856 by @dotnet-bot in dotnet/msbuild#12982 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#12979 * eliminate test data serialization warnings by @JanProvaznik in dotnet/msbuild#12983 * Add the feature flag that allows users to opt out automatic UTF8 console encoding by @GangWang01 in dotnet/msbuild#12637 * Polyfill clean up and source package organization by @DustinCampbell in dotnet/msbuild#12977 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13052367 by @dotnet-bot in dotnet/msbuild#12984 * Add documentation for enabling binlog collection via env var by @YuliiaKovalova in dotnet/msbuild#12805 * Support multiple binary logs from command line arguments by @Copilot in dotnet/msbuild#12706 * Add VcxprojReader.exe to ngenApplications by @YuliiaKovalova in dotnet/msbuild#12986 * Add HostServices support in Out-of-Process Task Host by @YuliiaKovalova in dotnet/msbuild#12753 * [main] Update dependencies from dotnet/roslyn by @dotnet-maestro[bot] in dotnet/msbuild#13002 * [main] Update dependencies from dotnet/arcade by @dotnet-maestro[bot] in dotnet/msbuild#13000 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13078382 by @dotnet-bot in dotnet/msbuild#13003 * Add telemetry tracking for task factory names and runtime usage by @Copilot in dotnet/msbuild#12989 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#12987 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13079827 by @dotnet-bot in dotnet/msbuild#13010 * Snap for VS 18.3 and update branding to VS 18.4 by @Copilot in dotnet/msbuild#13005 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#13012 * Add telemetry to categorize build failure reasons by @Copilot in dotnet/msbuild#13007 * Update MicrosoftBuildVersion in analyzer template by @github-actions[bot] in dotnet/msbuild#13011 * Update OptProf drop metadata configuration by @YuliiaKovalova in dotnet/msbuild#13020 * Fix MSB1025 error when using DistributedFileLogger (-dfl flag) by @Copilot in dotnet/msbuild#13036 * CmdLine parsing was extracted from XMake and the implementation is visible to dotnet (attempt 2) by @MichalPavlik in dotnet/msbuild#12836 * Make task environment path absolutization not throw. by @AR-May in dotnet/msbuild#13035 * Fix flaky test TestTerminalLoggerTogetherWithOtherLoggers by @Copilot in dotnet/msbuild#13044 * Enlighten more tasks that require no change by @AR-May in dotnet/msbuild#13045 * [main] Update dependencies from dotnet/roslyn by @dotnet-maestro[bot] in dotnet/msbuild#13050 * [main] Update dependencies from dotnet/arcade by @dotnet-maestro[bot] in dotnet/msbuild#13048 * Add support for MSBUILD_LOGGING_ARGS by @YuliiaKovalova in dotnet/msbuild#12993 * Fix MSBuildEventSource by @dfederm in dotnet/msbuild#13030 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13124182 by @dotnet-bot in dotnet/msbuild#13053 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#13031 * Add incrementality tracking support and more detailed analysis of the build errors reported by @YuliiaKovalova in dotnet/msbuild#13057 * [automated] Merge branch 'vs18.3' => 'main' by @github-actions[bot] in dotnet/msbuild#13055 * Enable com support for clr4 in task host by @YuliiaKovalova in dotnet/msbuild#13033 * Add 'rel/d18.3' to insertion target branch options by @ViktorHofer in dotnet/msbuild#13067 * add OriginalValue property to AbsolutePath by @JanProvaznik in dotnet/msbuild#13077 * [automated] Merge branch 'vs18.3' => 'main' by @github-actions[bot] in dotnet/msbuild#13074 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13137486 by @dotnet-bot in dotnet/msbuild#13075 * Refactor FileUtilities.cs and add methods for absolute paths. by @AR-May in dotnet/msbuild#13079 * Limit extended flag usage to NET and CLR4 runtimes by @YuliiaKovalova in dotnet/msbuild#13080 * [main] Update dependencies from nuget/nuget.client by @dotnet-maestro[bot] in dotnet/msbuild#13065 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13137926 by @dotnet-bot in dotnet/msbuild#13081 * Update to 10.0.1 references by @rainersigwald in dotnet/msbuild#13072 * Undo COM support in out of proc task host CLR4 by @YuliiaKovalova in dotnet/msbuild#13089 * Add Managed Identity for bootstrapper creation by @rainersigwald in dotnet/msbuild#13092 * Add warning MSB4280 when DOTNET_HOST_PATH is set to a directory by @Copilot in dotnet/msbuild#13091 ... (truncated) Commits viewable in [compare view](dotnet/msbuild@v18.3.3...v18.4.0). </details> [](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores) Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Updated [Microsoft.Build.Framework](https://github.com/dotnet/msbuild) from 18.3.3 to 18.4.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Build.Framework's releases](https://github.com/dotnet/msbuild/releases)._ ## 18.4.0 ## What's Changed * Fix terminal logger quiet mode to show project context for warnings/errors by @Copilot in dotnet/msbuild#12930 * Replace OpenTelemetry with Microsoft.VisualStudio.Telemetry for VS by @YuliiaKovalova in dotnet/msbuild#12843 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13050856 by @dotnet-bot in dotnet/msbuild#12982 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#12979 * eliminate test data serialization warnings by @JanProvaznik in dotnet/msbuild#12983 * Add the feature flag that allows users to opt out automatic UTF8 console encoding by @GangWang01 in dotnet/msbuild#12637 * Polyfill clean up and source package organization by @DustinCampbell in dotnet/msbuild#12977 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13052367 by @dotnet-bot in dotnet/msbuild#12984 * Add documentation for enabling binlog collection via env var by @YuliiaKovalova in dotnet/msbuild#12805 * Support multiple binary logs from command line arguments by @Copilot in dotnet/msbuild#12706 * Add VcxprojReader.exe to ngenApplications by @YuliiaKovalova in dotnet/msbuild#12986 * Add HostServices support in Out-of-Process Task Host by @YuliiaKovalova in dotnet/msbuild#12753 * [main] Update dependencies from dotnet/roslyn by @dotnet-maestro[bot] in dotnet/msbuild#13002 * [main] Update dependencies from dotnet/arcade by @dotnet-maestro[bot] in dotnet/msbuild#13000 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13078382 by @dotnet-bot in dotnet/msbuild#13003 * Add telemetry tracking for task factory names and runtime usage by @Copilot in dotnet/msbuild#12989 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#12987 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13079827 by @dotnet-bot in dotnet/msbuild#13010 * Snap for VS 18.3 and update branding to VS 18.4 by @Copilot in dotnet/msbuild#13005 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#13012 * Add telemetry to categorize build failure reasons by @Copilot in dotnet/msbuild#13007 * Update MicrosoftBuildVersion in analyzer template by @github-actions[bot] in dotnet/msbuild#13011 * Update OptProf drop metadata configuration by @YuliiaKovalova in dotnet/msbuild#13020 * Fix MSB1025 error when using DistributedFileLogger (-dfl flag) by @Copilot in dotnet/msbuild#13036 * CmdLine parsing was extracted from XMake and the implementation is visible to dotnet (attempt 2) by @MichalPavlik in dotnet/msbuild#12836 * Make task environment path absolutization not throw. by @AR-May in dotnet/msbuild#13035 * Fix flaky test TestTerminalLoggerTogetherWithOtherLoggers by @Copilot in dotnet/msbuild#13044 * Enlighten more tasks that require no change by @AR-May in dotnet/msbuild#13045 * [main] Update dependencies from dotnet/roslyn by @dotnet-maestro[bot] in dotnet/msbuild#13050 * [main] Update dependencies from dotnet/arcade by @dotnet-maestro[bot] in dotnet/msbuild#13048 * Add support for MSBUILD_LOGGING_ARGS by @YuliiaKovalova in dotnet/msbuild#12993 * Fix MSBuildEventSource by @dfederm in dotnet/msbuild#13030 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13124182 by @dotnet-bot in dotnet/msbuild#13053 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#13031 * Add incrementality tracking support and more detailed analysis of the build errors reported by @YuliiaKovalova in dotnet/msbuild#13057 * [automated] Merge branch 'vs18.3' => 'main' by @github-actions[bot] in dotnet/msbuild#13055 * Enable com support for clr4 in task host by @YuliiaKovalova in dotnet/msbuild#13033 * Add 'rel/d18.3' to insertion target branch options by @ViktorHofer in dotnet/msbuild#13067 * add OriginalValue property to AbsolutePath by @JanProvaznik in dotnet/msbuild#13077 * [automated] Merge branch 'vs18.3' => 'main' by @github-actions[bot] in dotnet/msbuild#13074 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13137486 by @dotnet-bot in dotnet/msbuild#13075 * Refactor FileUtilities.cs and add methods for absolute paths. by @AR-May in dotnet/msbuild#13079 * Limit extended flag usage to NET and CLR4 runtimes by @YuliiaKovalova in dotnet/msbuild#13080 * [main] Update dependencies from nuget/nuget.client by @dotnet-maestro[bot] in dotnet/msbuild#13065 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13137926 by @dotnet-bot in dotnet/msbuild#13081 * Update to 10.0.1 references by @rainersigwald in dotnet/msbuild#13072 * Undo COM support in out of proc task host CLR4 by @YuliiaKovalova in dotnet/msbuild#13089 * Add Managed Identity for bootstrapper creation by @rainersigwald in dotnet/msbuild#13092 * Add warning MSB4280 when DOTNET_HOST_PATH is set to a directory by @Copilot in dotnet/msbuild#13091 ... (truncated) Commits viewable in [compare view](dotnet/msbuild@v18.3.3...v18.4.0). </details> Updated [Microsoft.Build.Utilities.Core](https://github.com/dotnet/msbuild) from 18.3.3 to 18.4.0. <details> <summary>Release notes</summary> _Sourced from [Microsoft.Build.Utilities.Core's releases](https://github.com/dotnet/msbuild/releases)._ ## 18.4.0 ## What's Changed * Fix terminal logger quiet mode to show project context for warnings/errors by @Copilot in dotnet/msbuild#12930 * Replace OpenTelemetry with Microsoft.VisualStudio.Telemetry for VS by @YuliiaKovalova in dotnet/msbuild#12843 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13050856 by @dotnet-bot in dotnet/msbuild#12982 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#12979 * eliminate test data serialization warnings by @JanProvaznik in dotnet/msbuild#12983 * Add the feature flag that allows users to opt out automatic UTF8 console encoding by @GangWang01 in dotnet/msbuild#12637 * Polyfill clean up and source package organization by @DustinCampbell in dotnet/msbuild#12977 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13052367 by @dotnet-bot in dotnet/msbuild#12984 * Add documentation for enabling binlog collection via env var by @YuliiaKovalova in dotnet/msbuild#12805 * Support multiple binary logs from command line arguments by @Copilot in dotnet/msbuild#12706 * Add VcxprojReader.exe to ngenApplications by @YuliiaKovalova in dotnet/msbuild#12986 * Add HostServices support in Out-of-Process Task Host by @YuliiaKovalova in dotnet/msbuild#12753 * [main] Update dependencies from dotnet/roslyn by @dotnet-maestro[bot] in dotnet/msbuild#13002 * [main] Update dependencies from dotnet/arcade by @dotnet-maestro[bot] in dotnet/msbuild#13000 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13078382 by @dotnet-bot in dotnet/msbuild#13003 * Add telemetry tracking for task factory names and runtime usage by @Copilot in dotnet/msbuild#12989 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#12987 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13079827 by @dotnet-bot in dotnet/msbuild#13010 * Snap for VS 18.3 and update branding to VS 18.4 by @Copilot in dotnet/msbuild#13005 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#13012 * Add telemetry to categorize build failure reasons by @Copilot in dotnet/msbuild#13007 * Update MicrosoftBuildVersion in analyzer template by @github-actions[bot] in dotnet/msbuild#13011 * Update OptProf drop metadata configuration by @YuliiaKovalova in dotnet/msbuild#13020 * Fix MSB1025 error when using DistributedFileLogger (-dfl flag) by @Copilot in dotnet/msbuild#13036 * CmdLine parsing was extracted from XMake and the implementation is visible to dotnet (attempt 2) by @MichalPavlik in dotnet/msbuild#12836 * Make task environment path absolutization not throw. by @AR-May in dotnet/msbuild#13035 * Fix flaky test TestTerminalLoggerTogetherWithOtherLoggers by @Copilot in dotnet/msbuild#13044 * Enlighten more tasks that require no change by @AR-May in dotnet/msbuild#13045 * [main] Update dependencies from dotnet/roslyn by @dotnet-maestro[bot] in dotnet/msbuild#13050 * [main] Update dependencies from dotnet/arcade by @dotnet-maestro[bot] in dotnet/msbuild#13048 * Add support for MSBUILD_LOGGING_ARGS by @YuliiaKovalova in dotnet/msbuild#12993 * Fix MSBuildEventSource by @dfederm in dotnet/msbuild#13030 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13124182 by @dotnet-bot in dotnet/msbuild#13053 * [main] Source code updates from dotnet/dotnet by @dotnet-maestro[bot] in dotnet/msbuild#13031 * Add incrementality tracking support and more detailed analysis of the build errors reported by @YuliiaKovalova in dotnet/msbuild#13057 * [automated] Merge branch 'vs18.3' => 'main' by @github-actions[bot] in dotnet/msbuild#13055 * Enable com support for clr4 in task host by @YuliiaKovalova in dotnet/msbuild#13033 * Add 'rel/d18.3' to insertion target branch options by @ViktorHofer in dotnet/msbuild#13067 * add OriginalValue property to AbsolutePath by @JanProvaznik in dotnet/msbuild#13077 * [automated] Merge branch 'vs18.3' => 'main' by @github-actions[bot] in dotnet/msbuild#13074 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13137486 by @dotnet-bot in dotnet/msbuild#13075 * Refactor FileUtilities.cs and add methods for absolute paths. by @AR-May in dotnet/msbuild#13079 * Limit extended flag usage to NET and CLR4 runtimes by @YuliiaKovalova in dotnet/msbuild#13080 * [main] Update dependencies from nuget/nuget.client by @dotnet-maestro[bot] in dotnet/msbuild#13065 * Localized file check-in by OneLocBuild Task: Build definition ID 9434: Build ID 13137926 by @dotnet-bot in dotnet/msbuild#13081 * Update to 10.0.1 references by @rainersigwald in dotnet/msbuild#13072 * Undo COM support in out of proc task host CLR4 by @YuliiaKovalova in dotnet/msbuild#13089 * Add Managed Identity for bootstrapper creation by @rainersigwald in dotnet/msbuild#13092 * Add warning MSB4280 when DOTNET_HOST_PATH is set to a directory by @Copilot in dotnet/msbuild#13091 ... (truncated) Commits viewable in [compare view](dotnet/msbuild@v18.3.3...v18.4.0). </details> Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting `@dependabot rebase`. [//]: # (dependabot-automerge-start) [//]: # (dependabot-automerge-end) --- <details> <summary>Dependabot commands and options</summary> <br /> You can trigger Dependabot actions by commenting on this PR: - `@dependabot rebase` will rebase this PR - `@dependabot recreate` will recreate this PR, overwriting any edits that have been made to it - `@dependabot show <dependency name> ignore conditions` will show all of the ignore conditions of the specified dependency - `@dependabot ignore this major version` will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this minor version` will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself) - `@dependabot ignore this dependency` will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself) </details> Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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
MSBUILD_CONSOLE_USE_DEFAULT_ENCODINGto1.Testing
Manually tested.

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