How to fix codepage in nuget package manager console?

516 Views Asked by At

When I'm executing dotnet command in the nuget package manager, the output displayed in ANSI codepage instead of UTF8. Where can I find Visual Studio settings to change the characters encoding in that console?

PM> [System.Console]::OutputEncoding

IsSingleByte      : True
BodyName          : koi8-r
EncodingName      : Кириллица (Windows)
HeaderName        : windows-1251
WebName           : windows-1251
WindowsCodePage   : 1251
IsBrowserDisplay  : True
IsBrowserSave     : True
IsMailNewsDisplay : True
IsMailNewsSave    : True
EncoderFallback   : System.Text.InternalEncoderBestFitFallback
DecoderFallback   : System.Text.InternalDecoderBestFitFallback
IsReadOnly        : True
CodePage          : 1251

PM> dotnet tool install -g try-convert
dotnet : Рнструмент "try-convert" СѓР¶Рµ установлен.
строка:1 знак:1
+ dotnet tool install -g try-convert
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (РнструмР...ановлен.:String) [], RemoteException
    + FullyQualifiedErrorId : NativeCommandError
 
PM> dotnet tool update -g try-convert
Рнструмент "try-convert" был переустановлен СЃ последней стабильной версией (версией "0.9.232202").

enter image description here

The issue is present in Visual Studio 2019 and 2022, fully updated. OS: Windows 10 with Russian locale.

The only working solution I found was to set "UTF8 experimental feature" in the system locale settings. However, this feature broke some apps for me (like highlighting based on filenames in file manager).

1

There are 1 best solutions below

4
Bowman Zhu-MSFT On

Update:

I think I know what you want, you want the package manager console output Russian but don't effect whole VS Tool, right?

run the below command:

$null = cmd /c ''

$Global:OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()

And see the result:

enter image description here

You can see that the PM console output Russian on my side successfully.

By the way, if you want VS output Russian by default in PM console when the language of VS Tool is Russian, you can report it here:

https://developercommunity.visualstudio.com/VisualStudio/suggest

Original Answer:

I am able to reproduce your issue:

enter image description here

For this issue, just change the settings in this place should be ok:

enter image description here

enter image description here

After the above steps, restart the VS. Then the VS will be able to take utf8 in package manager console.