Change encoding on a per file or per extension basis

merv picture merv · Sep 5, 2012 · Viewed 35.3k times · Source

I'm using Microsoft Visual Studio Express 2012 for Web. It seems that every file which I open with it gets encoded into UTF-8. For most files which are going to be web-facing, that's fine. However, I have files in my projects that are specifically for build purposes (e.g., .bat files), which must be encoded in ANSI.

Are there any configuration settings in VS to either designate on a per file or a per extension basis the encoding? Or, if not specify the encoding, at least disable the auto-conversion to UTF-8?

Answer

Tbyang2004 picture Tbyang2004 · Aug 28, 2014

Open the problematic file in Visual Studio and...

  • On the File menu, click Advanced Save Options.
  • In the Encoding dropdown, select Unicode (UTF-8 … or the encoding you require.
  • Click OK.

Also see: how to change source file encoding in csharp project (visual studio / msbuild machine)?