I am searching for a way to setup Visual Studio so it always saves my files in UTF-8.
I have only found options to set this project wide. Is there a way to set it Visual Studio wide?
Select “Save As” from File menu, go to Save button and open its dropdown menu, select “Save with Encoding…”, choose “Unicode (UTF-8 without signature)”.
To open an encoded file that is part of a project In Solution Explorer, right-click the file and choose Open With. In the Open With dialog box, choose the editor to open the file with. Many Visual Studio editors, such as the forms editor, will auto-detect the encoding and open the file appropriately.
Do you want the files to save as UTF-8 because you are using special characters that would be lost in ASCII encoding? If that's the case, then there is a VS2008 global setting in Tools > Options > Environment > Documents
, named Save documents as Unicode when data cannot be saved in codepage
. When this is enabled, VS2008 will save as Unicode if certain characters cannot be represented in the otherwise-default codepage.
Also, which files are not being saved as UTF-8? All of my .cs, .csproj, .sln, .config, .as*x, etc, all save as UTF-8 (with signature, the byte order marks), by default.
It is possible with EditorConfig.
EditorConfig helps developers define and maintain consistent coding styles between different editors and IDEs.
This also includes file encoding.
EditorConfig is built-in Visual Studio 2017 by default, and I there were plugins available for versions as old as VS2012. Read more from EditorConfig Visual Studio Plugin page.
You can set up a EditorConfig configuration file high enough in your folder structure to span all your intended repos (up to your drive root should your files be really scattered everywhere) and configure the setting charset
:
charset: set to latin1, utf-8, utf-8-bom, utf-16be or utf-16le to control the character set.
You can add filters and exceptions etc on every folder level or by file name/type should you wish for finer control.
Once configured then compatible IDEs should automatically do it's thing to make matching files comform to set rules. Note that Visual Studio does not automatically convert all your files but do its bit when you work with files in IDE (open and save).
While you could have a Visual-studio-wide setup, I strongly suggest to still include an EditorConfig root to your solution version control, so that explicit settings are automatically synced to all team members as well. Your drive root editorconfig file can be the fallback should some project not have their own editorconfig files set up yet.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With