如何在NuGet包管理器控制台中修复代码页?

huangapple go评论52阅读模式
英文:

How to fix codepage in nuget package manager console?

问题

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][1]][1]

  [1]: https://i.stack.imgur.com/bUxNd.png

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).

<details>
<summary>英文:</summary>

When I&#39;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: (РнструмР...Р&#176;РЅРѕРІР&#187;Р&#181;РЅ.:String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
    
    

PM> dotnet tool update -g try-convert
Рнструмент "try-convert" был переустановлен СЃ последней стабильной версией (версией "0.9.232202").


[![enter image description here][1]][1]

  [1]: https://i.stack.imgur.com/bUxNd.png

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 &quot;UTF8 experimental feature&quot; in the system locale settings. However, this feature broke some apps for me (like highlighting based on filenames in file manager).

</details>


# 答案1
**得分**: 1

# Update:

我认为我知道你想要什么,你想要包管理器控制台输出俄语,但不影响整个VS工具,对吗?

运行以下命令:

$null = cmd /c ''
$Global:OutputEncoding = [Console]::InputEncoding = [Console]::OutputEncoding = [System.Text.UTF8Encoding]::new()


然后查看结果:

[![点击查看图片描述][1]][1]

你可以看到,在我的端口,包管理器控制台成功输出了俄语。

顺便说一下,如果你想要在VS工具的语言为俄语时默认在包管理器控制台中输出俄语,你可以在这里报告:

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

# 原始回答:

我能够复现你的问题:

[![点击查看图片描述][2]][2]

对于这个问题,只需在此处更改设置应该就可以了:

[![点击查看图片描述][3]][3]

[![点击查看图片描述][4]][4]

完成以上步骤后,重新启动VS。然后VS将能够在包管理器控制台中接受UTF8编码。

[1]: https://i.stack.imgur.com/pjTTZ.png
[2]: https://i.stack.imgur.com/rxumy.png
[3]: https://i.stack.imgur.com/OWAzd.png
[4]: https://i.stack.imgur.com/jHW4a.png

<details>
<summary>英文:</summary>

# Update:

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

run the below command:

`$null = cmd /c &#39;&#39;`

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

And see the result:

[![enter image description here][1]][1]

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][2]][2]

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

[![enter image description here][3]][3]

[![enter image description here][4]][4]

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


  [1]: https://i.stack.imgur.com/pjTTZ.png
  [2]: https://i.stack.imgur.com/rxumy.png
  [3]: https://i.stack.imgur.com/OWAzd.png
  [4]: https://i.stack.imgur.com/jHW4a.png

</details>



huangapple
  • 本文由 发表于 2023年4月17日 06:52:28
  • 转载请务必保留本文链接:https://go.coder-hub.com/76030702.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定