Skip to content
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

UTF encoding of auto generated code behind C# file changes when feature file text changes #1871

Closed
mikeoshea opened this issue Jan 30, 2020 · 5 comments · Fixed by #1933
Closed

Comments

@mikeoshea
Copy link

I came across an encoding issue when I upgraded from a direct DLL reference to Specflow version 2.2.0 - to a NuGet reference of version 3.1.7.4.

Now when I change text in my feature file, Specflow changes the encoding of its associated code behind C# file from UTF-8-BOM to UTF-8.

The manual fix is easy, you just open the .cs C# file in Notepad++, click the encoding menu and change it back from "Encode in UTF-8" to "Encode in UTF-8-BOM" and save the file.

This is obviously easily forgotten and annoying to remember!

@SabotageAndi
Copy link
Contributor

Interesting. I checked some code-behind files in 2 projects and they are all UTF-8.
We don't specify an encoding when we write the file: https://github.com/SpecFlowOSS/SpecFlow/blob/master/SpecFlow.Tools.MsBuild.Generation/CodeBehindWriter.cs

@mikeoshea
Copy link
Author

We have a script in our Cruise Control build verifying that the correct encoding (UTF-8-BOM) is being used (this is the default encoding of .cs files for C# when you add a new class in Visual Studio). After a feature file has changed, we are getting warnings when this nightly script is ran due to this issue, when we don't remember to change the encoding before committing to git.

@SabotageAndi
Copy link
Contributor

I made some research and found out that UTF-8 + BOM is really the default encoding for C#- files. That was a surprise for me, I always thought it was only UTF-8.

So I am happy to review and accept a PR that fixes this. Should not be a big change. I think only the File.WriteAllText calls in https://github.com/SpecFlowOSS/SpecFlow/blob/master/SpecFlow.Tools.MsBuild.Generation/CodeBehindWriter.cs has to be changed.

@mikeoshea
Copy link
Author

Thanks for researching the issue and accepting the change. This will remove one of these have to remember items for us in a future release of SpecFlow.

SabotageAndi added a commit that referenced this issue Apr 1, 2020
Fixes #1871

Co-authored-by: Andreas Willich <SabotageAndi@users.noreply.github.com>
@github-actions
Copy link

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants