What is the default encoding for source files in visual studio 2017

前端 未结 5 1039
独厮守ぢ
独厮守ぢ 2020-12-16 13:13

It seems visual studio 2017 always saves new files as UTF8-BOM. It also seems this was not the case with earlier versions of visual studio, but i could not find any documen

5条回答
  •  时光取名叫无心
    2020-12-16 13:23

    Apparently the "Advanced Save Options\Encoding" option has been removed from the "File" menu due to uncommon use. This was the reason given by a Visual Studio Team member (see this).

    The option is still there, but you have to do a couple extra clicks.

    1. In the menu strip, Go To FILE -> Save as
    2. When the Save File Dialog appears, the Save button has a down arrow. Click it.
    3. Select Save with Encoding...

    Once you save a file to a certain format (I believe the one you're looking for is Unicode (UTF-8 without signature) - Codepage 65001), Visual Studio should in theory not change it on a whim.

    Now here's the problem though, once you remove the BOM, no reader can really know with 100% certainty that a given text file is actually UTF-8. This is just from observing the behaviour, but if you go and Save as With Encoding... and select
    Unicode (UTF-8 without signature) - Codepage 65001 (which is UTF8 without BOM), the BOM will be removed.....however, when you close the file and reopen it, then go to Advanced Save Options again, you will notice that Visual Studio assumed that the text format was CodePage 1252. The file will of course be perfectly valid as it maps every possible byte value to some character, but that may give you strange results in some fringe cases.

    One thing it will not do, is add the BOM back in (at least I have never seen it). Hope this helps.

提交回复
热议问题