如何使Visual Studio将所有文件保存为UTF-8而无需在项目或解决方案级别签名? [英] How can I make Visual Studio save all files as UTF-8 without signature on Project or Solution level?

查看:962
本文介绍了如何使Visual Studio将所有文件保存为UTF-8而无需在项目或解决方案级别签名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图配置一个VS c ++项目,它可以在Linux中由gcc编译。似乎我需要的文件编码为UTF-8没有签名(这不是默认值)。是否可以在项目或解决方案级别上设置某些内容,以便在某人打开解决方案并保存其更改后,文件仍然是UTF-8?



请注意,这是一个开放项目,因此我不能要求所有人更改其Visual Studio设置。



如果你有Cygwin您可以使用此小脚本批量修改现有文件:

 查找。 -name* .cpp-exec vim -cset nobomb-c wq! {} \; 

或者,如果你没有Cygwin,但你有vim,你可以使用这个批处理脚本。

  for(* .cpp)do call vim -cset nobomb-c wq!请注意,在批处理脚本中执行此操作,似乎我需要按[返回]键,然后单击确定每次vim退出,而cygwin版本不是这样。


I am trying to configure a VS c++ project in a way that it can be compiled by gcc in Linux. It seems that I need the files to be encoded as UTF-8 without signature (which is not the default). Is it possible to set something on the project or solution level, so that after someone opens the solution and saves their changes the files are still UTF-8?

Please note that it is an open project, so I can't ask everyone to change their Visual Studio settings.

解决方案

Visual Studio will remove the BOM by going to Save As... and selecting "Save With Encoding..." and selecting "UTF-8 without signature". Once it is saved without the BOM, VS will not add it again. Unfortunately, there is no way to make this default for all files in VS and must be done manually each time a file is saved for the first time.

If you have Cygwin installed you can batch modify existing files with this little script:

find . -name "*.cpp" -exec vim -c "set nobomb" -c wq! {} \;

Or, if you don't have Cygwin but you do have vim you can use this batch script.

for %%f in (*.cpp) do call vim -c "set nobomb" -c wq! %%f

Note, doing this in a batch script, it seems I need to hit [return] each time vim exits which isn't the case with the cygwin version.

这篇关于如何使Visual Studio将所有文件保存为UTF-8而无需在项目或解决方案级别签名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆