Skip to content

Ensure all template code files(C#, F#, VB) have consistent BOM #41376

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

bjornen77
Copy link

@bjornen77 bjornen77 commented Jun 4, 2024

Ensure that all template code files in the repository are marked as UTF-8 BOM.

Fixes #41433

@bjornen77 bjornen77 requested a review from a team as a code owner June 4, 2024 12:36
@ghost ghost added Area-Common templates Covers templates in the repo (classlib, console, common item templates) untriaged Request triage from a team member labels Jun 4, 2024
@bjornen77 bjornen77 force-pushed the ensure-consistent-bom branch from 81474b4 to 83753e6 Compare June 4, 2024 12:37
@sharwell
Copy link
Member

sharwell commented Jun 4, 2024

I am strongly in favor of this, but I'm not a code owner in this repository.

@baronfel
Copy link
Member

baronfel commented Jun 4, 2024

We haven't yet decided that we will even take this approach to BOM usage. There is further discussion to be had.

Copy link
Member

@baronfel baronfel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Marking request changes to prevent merge

@bjornen77
Copy link
Author

We haven't yet decided that we will even take this approach to BOM usage. There is further discussion to be had.

I agree that it would be good to have some discussions and guidance regarding BOM usage.

This PR only makes the code file BOM usage consistent. Today all template code files already have BOM(except the two files changed in this PR)

@bjornen77 bjornen77 force-pushed the ensure-consistent-bom branch from 83753e6 to c358e09 Compare June 6, 2024 07:32
@richlander
Copy link
Member

Why? I'm not in favor of this.

My position: #39187

@GrabYourPitchforks

@bjornen77
Copy link
Author

I think that the main reason to include the UTF-8 BOM is to make sure Visual Studio opens the file as a UTF8 file(with BOM). Otherwise it will by default choose another encoding for the template file. This could lead to issues if you develop and save your file using Visual Studio on Windows and then run you program on Linux.

If Visual Studio changes it default "guess" to UTF8 instead of current behavior, omitting the BOM would be fine.

For more information see:
#39187 (comment)

@agocke
Copy link
Member

agocke commented Jul 9, 2024

The C# compiler behavior is to always try parsing as UTF-8 first, then go to other encodings. I don’t know the VS behavior.

I’m generally against BOM. I think it’s generally less portable than plain UTF-8. A lot of Unix tools don’t understand it.

@bjornen77 bjornen77 force-pushed the ensure-consistent-bom branch from c358e09 to a62621e Compare December 9, 2024 21:09
@bjornen77
Copy link
Author

bjornen77 commented Dec 9, 2024

Note that this PR only makes the SDK template files for C#, F#, and VB consistent regarding BOM usage. Currently, all C#, F#, and VB template files in the SDK include a BOM, except for two files. This PR fixes these two files and adds an editor config to ensure that future files also include a BOM, until a different decision is made.

I believe we should at least maintain consistency regarding BOM usage until we receive guidance or a decision on whether to include a BOM or not?

@bjornen77 bjornen77 changed the title Ensure all template code files have UTF-8 BOM Ensure all template code files(C#, F#, VB) have consistent BOM Dec 9, 2024
@richlander
Copy link
Member

Is there a VS issue filed on this? That would help.

I guess I'm not worried if we merge this PR or not since it doesn't change much.

@bjornen77
Copy link
Author

bjornen77 commented Dec 10, 2024

Is there a VS issue filed on this? That would help.

I guess I'm not worried if we merge this PR or not since it doesn't change much.

There have been many issues related to this reported over the years, for example:
https://developercommunity.visualstudio.com/t/vs-saves-files-without-bom-as-ansi-instead-of-utf/364271
https://developercommunity.visualstudio.com/t/utf-8-save-as-without-signature-default-request-to/787476

It seems that in Visual Studio 2022, version 17.3 Preview, there will be a new option to set the default encoding:
https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-notes-preview#productivity (default file encoding)

Perhaps this opens up the possibility of changing all templates to UTF-8 without BOM in .NET 10?
I am not sure if all other tools in the .NET ecosystem will work without BOM, but it might be a good idea to discuss this in #39187?

@bjornen77 bjornen77 force-pushed the ensure-consistent-bom branch from a62621e to b5e6efa Compare February 13, 2025 16:23
Ensured that all template code files in the repository are
marked as UTF-8 BOM.

Fixes dotnet#41433
@bjornen77 bjornen77 force-pushed the ensure-consistent-bom branch from b5e6efa to 0073bbc Compare February 14, 2025 09:18
@bjornen77
Copy link
Author

@baronfel Is there anything else that needs to be done for this PR? Have you had a chance to discuss it yet?

Just a note that this PR ensures consistency in BOM usage across SDK template files for C#, F#, and VB. Currently, all template files include a BOM except for two, which this PR fixes. It also adds an editor config to maintain consistency going forward unless a different decision is made.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Common templates Covers templates in the repo (classlib, console, common item templates) untriaged Request triage from a team member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Template code files does not have consistent BOM
5 participants