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

前端 未结 5 1059
独厮守ぢ
独厮守ぢ 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:30

    Also there has been an option "Advanced Save Options\Encoding" which did allow to change the encoding of newly saved files which is missing in VS2017.

    This feature Already exists! You can save files with specific character encoding to support bi-directional languages. You can also specify an encoding when opening a file, so that Visual Studio displays the file correctly.

    To save a file with encoding

    1. From the File menu, choose Save File As, and then click the drop-down button next to the Save button. The Advanced Save Options dialog box is displayed.
    2. Under Encoding, select the encoding to use for the file.
    3. Optionally, under Line endings, select the format for end-of-line characters.

    Are all files types saved with UTF8-BOM encoding in VS2017

    In my case, VS stores all the files with CodePage 1252 encoding.

    Is it possible to configure the encoding for new files in VS2017

    However, My Visual Studio version is 15.6.1 and some people have the same problem like yours in previous versions of 2017, but they said "We have fixed this issue and it's available in Visual Studio 2017 15.3"

    If not working, for C++ projects Take a look at /utf-8 (Set Source and Executable character sets to UTF-8).

    Will VS2017 change the encoding of "old" files which don't have UTF8-BOM

    By default, Visual Studio detects a byte-order mark to determine if the source file is in an encoded Unicode format, for example, UTF-16 or UTF-8. If no byte-order mark is found, it assumes the source file is encoded using the current user code page, unless you have specified a code page by using /utf-8 or the /source-charset option. Some people encountered a problem which is came from .editorconfig file, as below:

    root = true
    
    [*]
    indent_style = tab
    indent_size = 4
    tab_width = 4
    trim_trailing_whitespace = true
    insert_final_newline = true
    charset = utf-8 
    

    That final charset line is probable doing it... but I'm not asking for 'utf-8-with-bom'!

提交回复
热议问题