在 Visual Studio 中如何修改源代码文件的 Encoding?

今天在 github 网站中观察文件修改情况的时候,发现一个 .cs 文件中的汉字部分是乱码。意识到这是因为该文件的 Encoding 不是 UTF-8 造成的。

这篇文字介绍了如何修改一个源代码文件的 Encoding:

http://stackoverflow.com/questions/840065/how-to-change-source-file-encoding-in-csharp-project-visual-studio-msbuild-ma

Problem: Compiler launched from command line cannot process the source file because of international characters that I’ve just added.

Solution: Save source file explicitly in UTF-8 encoding to preserve international characters.

How To:

* open the problematic file in Visual Studio.

* on the File menu click “Advanced Save Options“

* from “Encoding” combo select “Unicode (UTF-8 …“

* click OK.

You’re set. Commit to please the build server and rest of the team waiting for green.

另一篇也有些参考价值:

http://stackoverflow.com/questions/696627/how-to-set-standard-encoding-in-visual-studio

Do you want the files to save as UTF-8 because you are using special characters that would be lost in ASCII encoding? If that's the case, then there is a VS2008 global setting in Tools > Options > Environment > Documents, named Save documents as Unicode when data cannot be saved in codepage. When this is enabled, VS2008 will save as Unicode if certain characters cannot be represented in the otherwise-default codepage.

Also, which files are not being saved as UTF-8? All of my .cs, .csproj, .sln, .config, .as*x, etc, all save as UTF-8 (with signature, the byte order marks), by default.


转载于:https://my.oschina.net/dpxietao/blog/412007

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值