Visual Studio 资源编辑器损坏了 UTF-8 编码的 rc 文件
Visual Studio Resource Editor corrupts rc files with UTF-8 encoding
Visual Studio 如果 .rc 文件在没有 UTF-8 BOM 的情况下保存,2019 和 2022 资源编辑器能够正确读取和显示 UTF-8 编码的 .rc 文件。
对它的主要要求,.rc文件必须包含有效的#pragma code_page
.
示例:
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(65001)
但是如果您对文本资源进行了一些更改并将结果保存回 .rc 文件,它将被损坏:
- 所有
#pragma code_page(65001)
将替换为您的默认 ANSI 代码页(例如 #pragma code_page(1252)
)
- 所有非 ANSI 符号将被替换为
?
。
有没有一些方法可以在 Visual Studio 201922 资源编辑器中使用 UTF-8 c++ 资源而没有这个错误。
P.S.:
- 我不使用 Unicode (UTF-16 LE) 编码,因为 git 中存在问题。
- 使用不带 BOM 的 UTF-8 是如何在 Visual Studio 中编译 UTF-8 .rc 文件的单一方式,请参阅 link。
Microsoft 知道这个错误,但他们决定不修复它:
Thank you very much for your feedback. We've decided to take no action on this feedback at the time.
When working with Resource Compiler (.rc) source files, our suggestion has always been to use UTF-16 whenever resources contain strings that cannot be encoded as ASCII. Based on your replies, it looks like switching back to UTF-16 would unblock your experience with Resource Editor, with the caveat that GitHub won't treat .rc files as text.
While eventually we want to support UTF-8 text encodings for .rc files, we currently do not have plans for this work; and for this reason we're closing this issue as Won't Fix.
Visual Studio 如果 .rc 文件在没有 UTF-8 BOM 的情况下保存,2019 和 2022 资源编辑器能够正确读取和显示 UTF-8 编码的 .rc 文件。
对它的主要要求,.rc文件必须包含有效的#pragma code_page
.
示例:
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NEUD)
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(65001)
但是如果您对文本资源进行了一些更改并将结果保存回 .rc 文件,它将被损坏:
- 所有
#pragma code_page(65001)
将替换为您的默认 ANSI 代码页(例如#pragma code_page(1252)
) - 所有非 ANSI 符号将被替换为
?
。
有没有一些方法可以在 Visual Studio 201922 资源编辑器中使用 UTF-8 c++ 资源而没有这个错误。
P.S.:
- 我不使用 Unicode (UTF-16 LE) 编码,因为 git 中存在问题。
- 使用不带 BOM 的 UTF-8 是如何在 Visual Studio 中编译 UTF-8 .rc 文件的单一方式,请参阅 link。
Microsoft 知道这个错误,但他们决定不修复它:
Thank you very much for your feedback. We've decided to take no action on this feedback at the time.
When working with Resource Compiler (.rc) source files, our suggestion has always been to use UTF-16 whenever resources contain strings that cannot be encoded as ASCII. Based on your replies, it looks like switching back to UTF-16 would unblock your experience with Resource Editor, with the caveat that GitHub won't treat .rc files as text.
While eventually we want to support UTF-8 text encodings for .rc files, we currently do not have plans for this work; and for this reason we're closing this issue as Won't Fix.