Yes, it's possible.
Force UTF-8 on all files
Use .editorconfig
as @Richard previously mentioned. Starting from Visual Studio v15.3, .editorconfig
support was fixed and improved. This simple .editorconfig
at the solution level would be enough to ensure each *.cs
is saved in UTF-8 without BOM:
root = true
[*.cs]
charset = utf-8
Moreover, it converts any existing file manually opened and saved by Visual Studio.
Convert all existing code files to UTF-8
I tested some answers from the thread Save all files in Visual Studio project as UTF-8 and they worked badly: non-Latin characters (Cyrillic in my case) had been converted into unreadable glyphs. On the contrary, Visual Studio itself does the "open-save" conversion flawlessly.
To automatically open and re-save all code files in a solution, use a simple R# trick:
- Set any R# code style rule appllicable to all your files to the value which strictly denies your company's code conventions. For example, braces layout is an obvious choice.
- Apply it to the whole solution using a
Code Cleanup
feature (Ctrl+E,C
by default). Choose a simplest built-in "Reformat Code" template to minimize changes.
- After all files have been formatted and saved, revert the R# rules back to their originals and run
Code Cleanup
once again.
All your *.cs
files should be saved in UTF-8 after that (the same idea for another file types supported by R#). Pretty formatting as a bonus.