How to config visual studio to use UTF-8 as the default encoding for all projects?

Visual Studio supports EditorConfig files (https://editorconfig.org/)

Visual Studio (VS2017 and later) searches for a file named ‘.editorconfig’ in the directory containing your source files, or anywhere above this directory in the hierarchy. This file can be used to direct the editor to use utf-8. I use the following:

[*]
end_of_line = lf
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
indent_style = space
indent_size = 4

The [*] line is a mask and means for all files – the scope of the commands can be reduced using e.g. [*.{h,cpp}]

There are further possibilities, particularly for C# files. Full details can be found at https://learn.microsoft.com/en-us/visualstudio/ide/create-portable-custom-editor-options?view=vs-2019

Leave a Comment