Force Visual Studio(2010)将所有文件保存在UTF-8中。

时间:2023-01-06 07:26:46

Is there any way I can force Visual Studio (2010) to save all files in UTF-8, always?

是否有办法让Visual Studio(2010)在UTF-8中保存所有文件?

3 个解决方案

#1


8  

I think it saves files in the current codepage. There's an option under Tools->Options->Environment->Documents that will make it save in unicode when it cannot save in current codepage. But I don't know if that helps...

我认为它保存了当前代码页中的文件。有一个选项在工具->选项->环境->文件,当它不能保存在当前代码页时,将使它保存在unicode中。但我不知道这是否有帮助…

#2


21  

I do not know of a way to force it to save everything in UTF-8, but you can do so on a case-by-case basis. When you first save a document and the Save As... dialog appears, the Save button will actually be a drop-down button with two options. You want "Save with Encoding...", which will then present you the entire list of installed Windows encodings.

我不知道有什么方法可以强制它保存UTF-8中的所有内容,但是您可以逐个进行。当您第一次保存文档时,保存为…对话框出现,Save按钮实际上是一个带有两个选项的下拉按钮。你想要“保存编码…”然后,它将向您展示安装的Windows编码的整个列表。

The encoding you really want is way down the bottom:

你真正想要的编码方式是:

Unicode (UTF-8 without signature) - Codepage 65001

Unicode (UTF-8无签名)- Codepage 65001。

although if you want to save yourself a lot of pain, you will probably want to pick the option near the top:

尽管如果你想为自己节省很多痛苦,你可能会想要选择接近顶部的选项:

Unicode (UTF-8 with signature) - Codepage 65001

Unicode(带有签名的UTF-8) - Codepage 65001。

The difference is that the latter option stick the UTF-8 signature (which is just the UTF-16 byte-order mark encoded in UTF-8). This is one of my pet peeves, as UTF-8 doesn't have multiple byte orders, so the BOM is redundant at best, and breaks all kinds of text processing tools at worst. MS uses it to "detect" UTF-8 automatically, since for single-byte character, UTF-8, ISO-8859-1, and CP-1252 are identical except for a sequence of 32 characters (0x80 - 0x9f) that MS basically made up.

区别在于后一种选择使用UTF-8签名(这只是UTF-8编码的UTF-16字节顺序标记)。这是我最讨厌的事情之一,因为UTF-8没有多个字节顺序,所以BOM最好是冗余的,并且在最坏的情况下破坏了所有类型的文本处理工具。MS使用它自动检测UTF-8,因为对于单字节字符,UTF-8、ISO-8859-1和CP-1252都是相同的,除了基本组成的32个字符序列(0x80 - 0x9f)。

If you only ever edit or process your files with Visual Studio or the .NET tools, then saving with signature will probably work fine. If you need to save files for use by other tools (batch files, SQL queries, PHP scripts, etc), the signature will cause problems, and you should save them without it. If you do this, you may want to enable the option (Under Tools -> Options -> Text Editor) to "Auto-detect UTF-8 encoding without signature", or else, right-click on the file and chose "Open With..." and select the editor option that says " editor with Encoding".

如果您只使用Visual Studio或。net工具编辑或处理您的文件,那么使用签名保存可能会工作得很好。如果您需要保存文件供其他工具使用(批处理文件、SQL查询、PHP脚本等),那么签名会导致问题,您应该在没有它的情况下保存它们。如果您这样做,您可能想要启用这个选项(在工具->选项->文本编辑器)中,“自动检测UTF-8编码,没有签名”,或者,右键单击文件,选择“Open With…”,并选择“编辑与编码”的编辑器选项。

#3


5  

I think you want to try ForceUtf8(with BOM)/ ForceUtf8(without BOM) extenstion.

我认为你想试一下(用BOM)/ ForceUtf8(没有BOM)扩展。

Just search UTF8 on VS extension gallery(Tools -> Extension and updates)

在VS扩展库中搜索UTF8(工具->扩展和更新)

#1


8  

I think it saves files in the current codepage. There's an option under Tools->Options->Environment->Documents that will make it save in unicode when it cannot save in current codepage. But I don't know if that helps...

我认为它保存了当前代码页中的文件。有一个选项在工具->选项->环境->文件,当它不能保存在当前代码页时,将使它保存在unicode中。但我不知道这是否有帮助…

#2


21  

I do not know of a way to force it to save everything in UTF-8, but you can do so on a case-by-case basis. When you first save a document and the Save As... dialog appears, the Save button will actually be a drop-down button with two options. You want "Save with Encoding...", which will then present you the entire list of installed Windows encodings.

我不知道有什么方法可以强制它保存UTF-8中的所有内容,但是您可以逐个进行。当您第一次保存文档时,保存为…对话框出现,Save按钮实际上是一个带有两个选项的下拉按钮。你想要“保存编码…”然后,它将向您展示安装的Windows编码的整个列表。

The encoding you really want is way down the bottom:

你真正想要的编码方式是:

Unicode (UTF-8 without signature) - Codepage 65001

Unicode (UTF-8无签名)- Codepage 65001。

although if you want to save yourself a lot of pain, you will probably want to pick the option near the top:

尽管如果你想为自己节省很多痛苦,你可能会想要选择接近顶部的选项:

Unicode (UTF-8 with signature) - Codepage 65001

Unicode(带有签名的UTF-8) - Codepage 65001。

The difference is that the latter option stick the UTF-8 signature (which is just the UTF-16 byte-order mark encoded in UTF-8). This is one of my pet peeves, as UTF-8 doesn't have multiple byte orders, so the BOM is redundant at best, and breaks all kinds of text processing tools at worst. MS uses it to "detect" UTF-8 automatically, since for single-byte character, UTF-8, ISO-8859-1, and CP-1252 are identical except for a sequence of 32 characters (0x80 - 0x9f) that MS basically made up.

区别在于后一种选择使用UTF-8签名(这只是UTF-8编码的UTF-16字节顺序标记)。这是我最讨厌的事情之一,因为UTF-8没有多个字节顺序,所以BOM最好是冗余的,并且在最坏的情况下破坏了所有类型的文本处理工具。MS使用它自动检测UTF-8,因为对于单字节字符,UTF-8、ISO-8859-1和CP-1252都是相同的,除了基本组成的32个字符序列(0x80 - 0x9f)。

If you only ever edit or process your files with Visual Studio or the .NET tools, then saving with signature will probably work fine. If you need to save files for use by other tools (batch files, SQL queries, PHP scripts, etc), the signature will cause problems, and you should save them without it. If you do this, you may want to enable the option (Under Tools -> Options -> Text Editor) to "Auto-detect UTF-8 encoding without signature", or else, right-click on the file and chose "Open With..." and select the editor option that says " editor with Encoding".

如果您只使用Visual Studio或。net工具编辑或处理您的文件,那么使用签名保存可能会工作得很好。如果您需要保存文件供其他工具使用(批处理文件、SQL查询、PHP脚本等),那么签名会导致问题,您应该在没有它的情况下保存它们。如果您这样做,您可能想要启用这个选项(在工具->选项->文本编辑器)中,“自动检测UTF-8编码,没有签名”,或者,右键单击文件,选择“Open With…”,并选择“编辑与编码”的编辑器选项。

#3


5  

I think you want to try ForceUtf8(with BOM)/ ForceUtf8(without BOM) extenstion.

我认为你想试一下(用BOM)/ ForceUtf8(没有BOM)扩展。

Just search UTF8 on VS extension gallery(Tools -> Extension and updates)

在VS扩展库中搜索UTF8(工具->扩展和更新)