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?
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?
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.
I work with Windows7.
Control Panel - Region and Language - Administrative - Language for non-Unicode programs.
After I set "Change system locale" to English(United States). My default encoding of vs2010 change to Windows-1252
. It was gb2312
before.
I created a new .cpp
file for a C++ project, after checking in the new file to TFS the encoding show Windows-1252 from the properties page of the file.
It is an old topic, but I'll put here what helped me: Change Visual Studio default encoding
Visual Studio default encoding format is UTF-8, but it has built-in encoding formats for various languages, which can be selected according to your needs. Generally, UTF-8 can be kept, because programs are usually written in English, so compatibility is better. It runs in most language systems and does not cause exceptions because they can be identified.
You set the default encoding format in the "Advanced Save Options" dialog box in Visual Studio, it can be opened through the "File" menu; but sometimes, it does not show "Advanced Save Options" in the "File" menu and is displayed.
Click "Tools", select "Customize" in the pop-up menu to open the "Customize" dialog box; select the "Commands" tab, click the drop-down list box to the right of the "Menu bar", and select "File" from the pop-up options; Click "Add Command", in the dialog box that opens, select "File" in the left list box, select "Advanced Save Options" in the right list box; click "OK", it is added to the" File "menu.
Click "File", select "Advanced Save Options" in the pop-up menu. Open the "Advanced Save Options" dialog box, and the currently set encoding is "US-ASCII - Codepage 20127".
Click the "Encoding" drop-down list box, drag the scroll bar to the top, and select "Unicode (UTF-8 with signature) - Codepage 65001".
Click the "OK", then Visual Studio sets the default encoding format to UTF-8.
The Problem is Windows/Microsoft applications put byte order marks at the beginning of all your files when saving as non-ASCII types (UTF-8, etc.). Other applications often break when they read these odd Microsoft UTF-8 byte order encoding marks at the top of files.
A perfect example of this problem was triggering quirsksmode in old IE web browsers when encoding in UTF-8 as browsers often displayed XHTML web pages based on what encoding falls at the start of the page. It makes a mess when other applications view those UTF-8 Visual Studio pages.
I usually do not recommend Visual Studio Extensions, but I do this one to fix that issue:
Fix File Encoding: https://vlasovstudio.com/fix-file-encoding/
The FixFileEncoding above install REMOVES the byte order mark and forces VS to save ALL FILES without a Byte Order Mark signature in UTF-8 at the top of all .NET pages. After installing go to Tools > Option then choose "FixFileEncoding". It should allow you to set all saves as UTF-8 . Add "cshtml to the list of files to always save in UTF-8 without the byte order mark as so: ".(htm|html|cshtml)$)".
Now open one of your files in Visual Studio. To verify its saving as UTF-8 go to File > Save As, then under the Save button choose "Save With Encoding". It should choose "UNICODE (Save without Signature)" by default from the list of encodings. Now when you save that page it should always save as UTF-8 without byte order mark at the beginning of the file when saving in Visual Studio.
I don't know of a global setting nither but you can try this: