-2

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
    Please [edit] your question to improve your [mcve]. In particular, run and share `[System.Console]::OutputEncoding` in nuget package manager console. Please [*do not* use (sole) images of code/data/errors](https://meta.stackoverflow.com/a/285557/3439404) in your [mcve]. Copy the actual text, paste it into the question, then format it as code. Post a hexadecimal dump in case of (partially) binary content. – JosefZ Apr 17 '23 at 18:01
  • 1
    Try `[System.Console]::InputEncoding = [System.Console]::OutputEncoding = [System.Text.Encoding]::UTF8` _before_ `dotnet …` command. BTW, you face a [mojibake](https://en.wikipedia.org/wiki/Mojibake) case (*example in Python for its universal intelligibility*): `'Инструмент "try-convert" уже установлен'.encode( 'utf-8').decode( 'cp1251', 'ignore')` returns `Рнструмент "try-convert" СѓР¶Рµ установлен`… – JosefZ Apr 17 '23 at 19:40
  • The latter output from `dotnet tool update -g try-convert` is `Инструмент "try-convert" был переустановлен с последней стабильной версией (версией "0.9.232202").` BTW, I have switched to [UTF-8 Everywhere](https://utf8everywhere.org/) long ago, incl. Windows _BETA UTF8 experimental feature_ with _no_ undesirable effect… – JosefZ Apr 17 '23 at 20:23

1 Answers1

1

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.

Bowman Zhu-MSFT
  • 4,776
  • 1
  • 9
  • 10
  • Well, +1 for a temporarily walkaround. But, this brings me more problems than a solution: https://imgur.com/tUrFQL6 2023 year, and VS has children problems, which are change a language for a whole application just to fix a single and commonly used feature :) – Alex Dragokas Apr 17 '23 at 15:26
  • 1
    @AlexDragokas See my latest update, I provide the script to change the behavior of PM output, and I think that should be the solution. :) – Bowman Zhu-MSFT Apr 18 '23 at 08:39
  • @AlexDragokas Hi Alex, have you checked my updated answer, does it answer your question? :) – Bowman Zhu-MSFT Apr 19 '23 at 01:34
  • the mentioned command work, thank you. However, I'm unhappy to enter such a long command each time I need a single nuget package. – Alex Dragokas Apr 20 '23 at 12:09