Skip to content

Shall we unify the file encodings of C# source files? #302

Closed

Description

@linmajia

C# source files have different file encodings. E.g. some have UTF-8 with BOM file encoding, while some have ASCII encoding.

image

Activity

  1. sharwell commented on Jun 5, 2018

    @sharwell
    Contributor

    I would recommend using .editorconfig for this. Here's the configuration line from dotnet/roslyn:
    https://github.com/dotnet/roslyn/blob/969249c9a2bf6ab6ded98d9e7702e76d5ebd6bf1/.editorconfig#L15

    The pull request where this was adopted, dotnet/roslyn#20541, includes the C# Interactive lines used to implement the change. Be aware that in some cases, it may be necessary to manually correct characters that are misinterpreted or have been in the past.

    ⚠️ It's very important to note that while UTF-8 without BOM is generally the preferred Unicode encoding, it does not work in practice the way one would expect. See dotnet/roslyn#20541 (comment) and dotnet/corefx#1470 (comment) for a couple other cases where this was discussed in the past.

  2. sharwell commented on Jun 5, 2018

    @sharwell
    Contributor

    If the team working on this repository would like, I would be happy to submit a pull request to implement this change. Just let me know; since it's a question of code style I would prefer to not offer the change until after it's deemed desirable. 😄

  3. veikkoeeva commented on Jun 5, 2018

    @veikkoeeva
    Contributor

    @sharwell 👍 from here, apply other settings too (e.g. the namespace ones). :)

  4. shauheen commented on Dec 6, 2018

    @shauheen
    Contributor

    Generally I would agree with adopting what roslyn does. @TomFinley what do you think?

  5. jwood803 commented on May 5, 2020

    @jwood803
    Contributor

    I was messing with this and after applying this to the solution, it also updated some spacing. Is there anything else we want to include that's similar to what the Roslyn project has such as the indent size?

    cc// @shauheen @sharwell

  6. michaelgsharp commented on Jul 28, 2021

    @michaelgsharp
    Contributor

    @jwood803 do you still have the branch where you were messing around with this? I realize its been a while, figured it would be worth asking.

    How much spacing was updated? It would probably be better to move towards what Roslyn or runtime has. Maybe not all in one PR, we could do it over several, but if you already have this file format issue fixed we could start there.

  7. jwood803 commented on Jul 28, 2021

    @jwood803
    Contributor

    @michaelgsharp Looking at my branches I don't think I created one for this. I can make these again and do a branch or draft PR for a review or discussion if that works.

  8. michaelgsharp commented on Jul 28, 2021

    @michaelgsharp
    Contributor

    If you are willing to do it that would be awesome.

  9. rosebyte commented on Sep 3, 2026

    @rosebyte
    Member

    C# source encoding is now standardised as UTF-8 with BOM through .editorconfig.

  10. locked and limited conversation to collaborators on Oct 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions