【问题标题】:How to config visual studio to use UTF-8 as the default encoding for all projects?如何配置 Visual Studio 以使用 UTF-8 作为所有项目的默认编码?
【发布时间】:2017-05-11 03:38:43
【问题描述】:

我进行了搜索,但只找到了更改单个文件编码的方法。我想使用已配置为 UTF-8 的编码启动项目。

【问题讨论】:

标签: visual-studio encoding utf-8


【解决方案1】:

我找到了两种方法

备用

还有其他方法,请尝试

Tools->Options->Environment->Documents

最后一个

如果不能,您可以尝试将其另存为 UTF-8,您可以使用高级选项另存为

【讨论】:

  • 这个选项现在已经隐藏在“另存为...”下,然后是保存旁边的箭头!
  • VS 2019 社区版没有这个选项。
【解决方案2】:

Visual Studio 支持 EditorConfig 文件 (https://editorconfig.org/)

Visual Studio(VS2017 及更高版本)在包含源文件的目录或层次结构中此目录上方的任何位置搜索名为“.editorconfig”的文件。该文件可用于指示编辑器使用 utf-8。我使用以下内容:

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4

[*] 行是所有文件的掩码和手段 - 可以使用例如缩小命令范围[*.{h,cpp}]

还有更多的可能性,尤其是对于 C# 文件。完整详情请见https://docs.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019

【讨论】:

    【解决方案3】:

    可以将语言环境代码页设置为 65001,VS 将使用 utf-8 保存所有文件。 https://en.wikipedia.org/wiki/Unicode_in_Microsoft_Windows#UTF-8

    但是由于是beta功能,所以会有一些bug。

    也参考https://superuser.com/questions/1033088/is-it-possible-to-set-locale-of-a-windows-application-to-utf-8/1451686

    【讨论】:

      【解决方案4】:

      工具->选项->文本编辑器->常规

      【讨论】:

      • 即使在 Visual Studio 2019 中,也没有 UTF8-default-encoding。最接近的选项是“Auto-detect UTF-8 encoding without signature”,这是不一样的。
      猜你喜欢
      • 2011-08-07
      • 2016-08-06
      • 2012-03-10
      • 2012-02-01
      • 1970-01-01
      • 2014-04-23
      • 2014-04-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多