Visual Studio 2017 中源文件的默认编码是什么?

What is the default encoding for source files in Visual Studio 2017?(Visual Studio 2017 中源文件的默认编码是什么?)
本文介绍了Visual Studio 2017 中源文件的默认编码是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎 Visual Studio 2017 总是将新文件保存为 UTF8-BOM.早期版本的 Visual Studio 似乎也不是这种情况,但我找不到任何文档.

还有一个选项高级保存选项编码";这确实允许更改 VS2017 中缺少的新保存文件的编码.

问题:

  • 在 VS2017 中是否所有文件类型都使用 UTF8-BOM 编码保存?
  • VS2017中是否可以为新文件配置编码?
  • VS2017 会改变旧"的编码吗?没有 UTF8-BOM 的文件?
  • 是否有关于此主题的文档?

解决方案

还有一个选项高级保存选项编码"确实允许更改丢失的新保存文件的编码在 VS2017 中.

使用编码保存文件

  1. 文件菜单中,选择将文件另存为,然后点击保存按钮旁边的下拉按钮.高级保存选项显示对话框.
  2. 在编码下,选择文件使用的编码.
  3. (可选)在行尾下,选择行尾的格式字符.

<块引用>

VS2017中所有文件类型都是用UTF8-BOM编码保存的吗

在我的例子中,VS 使用 CodePage 1252 编码存储所有文件.

<块引用>

是否可以在VS2017中为新文件配置编码

但是,我的 Visual Studio 版本是 15.6.1,有些人在 2017 年以前的版本中遇到了和你一样的问题,但是 他们说 "我们已经解决了这个问题,它在 Visual Studio 2017 15.3 中可用"

如果不工作,对于 C++ 项目请查看 /utf-8(将源和可执行字符集设置为 UTF-8).

<块引用>

VS2017 会改变旧"文件的编码吗?UTF8-BOM

默认情况下,Visual Studio 会检测字节顺序标记以确定源文件是否采用编码的 Unicode 格式,例如 UTF-16 或 UTF-8.如果未找到字节顺序标记,则假定源文件使用当前用户代码页进行编码,除非您使用/utf-8 或/source-charset 选项指定了代码页.有些人遇到了问题,它来自.editorconfig 文件,如下:

root = true[*]indent_style = 制表符缩进大小 = 4tab_width = 4trim_trailing_whitespace = trueinsert_final_newline = 真字符集 = utf-8

最后的 charset 行很可能会这样做...但我不是要'utf-8-with-bom'!

It seems Visual Studio 2017 always saves new files as UTF8-BOM. It also seems this was not the case with earlier versions of Visual Studio, but I could not find any documentation.

Also there has been an option "Advanced Save OptionsEncoding" which did allow to change the encoding of newly saved files which is missing in VS2017.

Questions:

  • Are all file types saved with UTF8-BOM encoding in VS2017?
  • Is it possible to configure the encoding for new files in VS2017?
  • Will VS2017 change the encoding of "old" files which don't have UTF8-BOM?
  • Is there any documentation about this topic?

解决方案

Also there has been an option "Advanced Save OptionsEncoding" which did allow to change the encoding of newly saved files which is missing in VS2017.

This feature Already exists! You can save files with specific character encoding to support bi-directional languages. You can also specify an encoding when opening a file, so that Visual Studio displays the file correctly.

Tosaveafilewithencoding

  1. From the File menu, choose Save File As, and then click the drop-down button next to the Save button. The Advanced Save Options dialog box is displayed.
  2. Under Encoding, select the encoding to use for the file.
  3. Optionally, under Line endings, select the format for end-of-line characters.

Are all files types saved with UTF8-BOM encoding in VS2017

In my case, VS stores all the files with CodePage 1252 encoding.

Is it possible to configure the encoding for new files in VS2017

However, My Visual Studio version is 15.6.1 and some people have the same problem like yours in previous versions of 2017, but they said "We have fixed this issue and it's available in Visual Studio 2017 15.3"

If not working, for C++ projects Take a look at /utf-8 (Set Source and Executable character sets to UTF-8).

Will VS2017 change the encoding of "old" files which don't have UTF8-BOM

By default, Visual Studio detects a byte-order mark to determine if the source file is in an encoded Unicode format, for example, UTF-16 or UTF-8. If no byte-order mark is found, it assumes the source file is encoded using the current user code page, unless you have specified a code page by using /utf-8 or the /source-charset option. Some people encountered a problem which is came from .editorconfig file, as below:

root = true

[*]
indent_style = tab
indent_size = 4
tab_width = 4
trim_trailing_whitespace = true
insert_final_newline = true
charset = utf-8 

That final charset line is probable doing it... but I'm not asking for 'utf-8-with-bom'!

这篇关于Visual Studio 2017 中源文件的默认编码是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

DispatcherQueue null when trying to update Ui property in ViewModel(尝试更新ViewModel中的Ui属性时DispatcherQueue为空)
Drawing over all windows on multiple monitors(在多个监视器上绘制所有窗口)
Programmatically show the desktop(以编程方式显示桌面)
c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
LINQ many-to-many relationship, how to write a correct WHERE clause?(LINQ多对多关系,如何写一个正确的WHERE子句?)