Bug Description
dotnet.exe change the code page of the attached terminal to be 65001 (i.e UTF-8) when the standard output of the dotnet.exe process is redirected. (it does not occur with dotnet.exe of .Net 6 SDK)
Illustration:


Impact Of The Bug
This bug break our build.
The terminal code page is a global setting and changing it impacts how following process will run. In our case, it breaks our build system based on ninja. Indeed, our build system run both MSVC C++ compiler and dotnet.exe, and MSVC C++ compiler depends on the code page to decide on its stdout encoding. Having the MSVC C++ compiler encoding changing randomly in the middle of the build creates issues.
How To Visualize The Terminal Code Page
To understand the bug it is important to be able to display the current code page of the terminal. I have created simple ShowConsoleCP.exe tool to do so which call and display the result of GetConsoleCP() and GetConsoleOutputCP()'s Win32 API. The tool is available in this ReproCodePage.zip archive.
How To Reproduce The Bug
Simple way: you can run the run_repro.cmd script of ReproCodePage.zip
Detailed way:
- Start a terminal
- create a new dotnet project. (e.g
dotnet new console HelloWorld)
- visualize the current terminal code page (e.g use ShowConsoleCP.exe included in ReproCodePage.zip)
- If the code page is 65001, set another code page and go back to step 3 (e.g run
chcp 932)
- build using
dotnet and redirect its standard output. (e.g dotnet build HelloWorld > foo.txt)
- Visualize the current terminal code page and noticed it is now 65001 instead of the one before
Further technical details
- I have been able to reproduce the bug using various process creation api and stdout redirection:
- using cmd.exe
> symbol to redirect to file
- using python and creation the dotnet.exe process with python's subprocess module
- using Win32 API's
CreateProcessA in a custom C++ application.
- This bug is introduced by .Net 7 SDK. I confirmed that by uninstalling the .Net 7.0.102 SDK and getting back to .Net 6.0.113 SDK the bug described above does not occure anymore.
- My
dotnet --info:
.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480
Runtime Environment:
OS Name: Windows
OS Version: 10.0.19045
OS Platform: Windows
RID: win10-x64
Base Path: C:\Program Files\dotnet\sdk\7.0.102\
Host:
Version: 7.0.2
Architecture: x64
Commit: d037e070eb
.NET SDKs installed:
3.1.426 [C:\Program Files\dotnet\sdk]
5.0.102 [C:\Program Files\dotnet\sdk]
5.0.303 [C:\Program Files\dotnet\sdk]
5.0.408 [C:\Program Files\dotnet\sdk]
5.0.416 [C:\Program Files\dotnet\sdk]
7.0.100 [C:\Program Files\dotnet\sdk]
6.0.112 [C:\Program Files\dotnet\sdk]
6.0.113 [C:\Program Files\dotnet\sdk]
8.0.102 [C:\Program Files\dotnet\sdk]
.NET runtimes installed:
Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.WindowsDesktop.App 3.1.32 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.12 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 6.0.13 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Microsoft.WindowsDesktop.App 7.0.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
Other architectures found:
arm64 [C:\Program Files\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
x86 [C:\Program Files (x86)\dotnet]
registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Bug Description
dotnet.exe change the code page of the attached terminal to be 65001 (i.e UTF-8) when the standard output of the dotnet.exe process is redirected. (it does not occur with dotnet.exe of .Net 6 SDK)
Illustration:


Impact Of The Bug
This bug break our build.
The terminal code page is a global setting and changing it impacts how following process will run. In our case, it breaks our build system based on ninja. Indeed, our build system run both MSVC C++ compiler and dotnet.exe, and MSVC C++ compiler depends on the code page to decide on its stdout encoding. Having the MSVC C++ compiler encoding changing randomly in the middle of the build creates issues.
How To Visualize The Terminal Code Page
To understand the bug it is important to be able to display the current code page of the terminal. I have created simple
ShowConsoleCP.exetool to do so which call and display the result ofGetConsoleCP()andGetConsoleOutputCP()'s Win32 API. The tool is available in this ReproCodePage.zip archive.How To Reproduce The Bug
Simple way: you can run the
run_repro.cmdscript of ReproCodePage.zipDetailed way:
dotnet new console HelloWorld)chcp 932)dotnetand redirect its standard output. (e.gdotnet build HelloWorld > foo.txt)Further technical details
>symbol to redirect to fileCreateProcessAin a custom C++ application.dotnet --info: