Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there a way to force VS to use Unicode always, instead of weird ISO-something?

I'm working on a winapp csproject using Visual Studio 2008 on Vista (Polish locale). The problem appears when I build the project on Win Server 2003 (English locale) - then Polish diacritic is gone.

I investigated that the issue is caused by improper source file encoding. It looks that source files aren't using UTF-8 encoding.

like image 536
tomo Avatar asked May 08 '09 14:05

tomo


People also ask

How do I change the default encoding in Visual Studio?

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.

How do I check the encoding of a file in Visual Studio?

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. If you choose an editor that allows you to choose an encoding, the Encoding dialog box is displayed.


1 Answers

Problem: Compiler launched from command line cannot process the source file because of international characters that I’ve just added.

Solution: Save source file explicitly in UTF-8 encoding to preserve international characters.

How To:

  • open the problematic file in Visual Studio.
  • on the File menu click “Advanced Save Options“
  • from “Encoding” combo select “Unicode (UTF-8 …“
  • click OK.

You’re set. Commit to please the build server and rest of the team waiting for green.

like image 84
ruslander Avatar answered Oct 03 '22 13:10

ruslander