如何强制Visual Studio在UTF-8编码的CSS文件开始时对BOM表示尊重?

时间:2021-02-20 22:22:50

Apparently, when Visual Studio 2008 (SP1) opens a CSS file, it doesn't recognize the UTF8 BOM marker as a BOM, but instead interprets it as text (first three characters show up as , but shouldn't be visible). While VS normally doesn't save the CSS files with a BOM, I'd expect the IDE to recognize and respect the BOM when it's there.

显然,当Visual Studio 2008 (SP1)打开一个CSS文件时,它不承认UTF8 BOM标记为BOM,而是将其解释为文本(前三个字符显示为i»,但不应该是可见的)。虽然VS通常不会用BOM保存CSS文件,但我希望IDE能够识别并尊重BOM。

This may be a bug with Visual Studio, however, does anyone know a workaround?

这可能是Visual Studio的一个缺陷,但是,有人知道解决方案吗?

1 个解决方案

#1


3  

This appeared to be a bug in Visual Studio 2008 SP1. Once it misinterprets the CSS file, it will continue misinterpreting it. Signs on the sand were, too, that rightclicking and selecting "Open With" did not work for any internal editor.

这似乎是Visual Studio 2008 SP1中的一个bug。一旦它误解了CSS文件,它将继续误解它。沙地上的标识也是,右击并选择“Open With”对任何内部编辑器都不起作用。

Closing Visual Studio and reopening it didn't work. What worked eventually was:

关闭Visual Studio并重新打开它并没有效果。工作最终是什么:

  • Rightclick the CSS file, select Open With and select CSS Source Editor With Encoding
  • 右击CSS文件,选择Open With,选择带有编码的CSS源编辑器
  • Click Set as Default, then click OK. Nothing will happen.
  • 单击默认设置,然后单击OK。什么都不会发生。
  • Close all editors. Close Visual Studio
  • 关闭所有编辑器。关闭Visual Studio
  • Reopen Visual Studio and your solution or project.
  • 重新打开Visual Studio和您的解决方案或项目。
  • Double click the CSS file. It will ask for the encoding. Select Auto. It should now open correctly.
  • 双击CSS文件。它会要求编码。选择汽车。现在它应该正确地打开了。
  • Rightclick again and set the default editor back to CSS Source Editor (otherwise you'll always have to select the encoding manually).
  • 再次右键单击并将默认编辑器设置为CSS源编辑器(否则必须手动选择编码)。

Or in short: associate with "With Encoding", restart VS, open CSS correctly with encoding "Auto", re-associate with default CSS Editor, done.

简而言之:关联到“与编码”,重新启动VS,正确地打开CSS与编码“Auto”,重新关联到默认的CSS编辑器,完成。

#1


3  

This appeared to be a bug in Visual Studio 2008 SP1. Once it misinterprets the CSS file, it will continue misinterpreting it. Signs on the sand were, too, that rightclicking and selecting "Open With" did not work for any internal editor.

这似乎是Visual Studio 2008 SP1中的一个bug。一旦它误解了CSS文件,它将继续误解它。沙地上的标识也是,右击并选择“Open With”对任何内部编辑器都不起作用。

Closing Visual Studio and reopening it didn't work. What worked eventually was:

关闭Visual Studio并重新打开它并没有效果。工作最终是什么:

  • Rightclick the CSS file, select Open With and select CSS Source Editor With Encoding
  • 右击CSS文件,选择Open With,选择带有编码的CSS源编辑器
  • Click Set as Default, then click OK. Nothing will happen.
  • 单击默认设置,然后单击OK。什么都不会发生。
  • Close all editors. Close Visual Studio
  • 关闭所有编辑器。关闭Visual Studio
  • Reopen Visual Studio and your solution or project.
  • 重新打开Visual Studio和您的解决方案或项目。
  • Double click the CSS file. It will ask for the encoding. Select Auto. It should now open correctly.
  • 双击CSS文件。它会要求编码。选择汽车。现在它应该正确地打开了。
  • Rightclick again and set the default editor back to CSS Source Editor (otherwise you'll always have to select the encoding manually).
  • 再次右键单击并将默认编辑器设置为CSS源编辑器(否则必须手动选择编码)。

Or in short: associate with "With Encoding", restart VS, open CSS correctly with encoding "Auto", re-associate with default CSS Editor, done.

简而言之:关联到“与编码”,重新启动VS,正确地打开CSS与编码“Auto”,重新关联到默认的CSS编辑器,完成。