File encoding is not maintained when first line of file is a conditional statement
See original GitHub issueThe file generated after doing dotnet new
has a different encoding than what was in the original file for the template.
Repro:
- Install dotnet 3.1 sdk
- Unzip
C:\Program Files\dotnet\templates\3.1.0\microsoft.dotnet.web.projecttemplates.3.1.3.1.0.nupkg
and go toWeb.ProjectTemplates/content/BlazorServerWeb-Csharp/
- Verify the encoding of
App.razor
(It should be UTF-8 with BOM) - Now create a new app with
dotnet new blazor
- Open the generated
App.razor
and check its encoding
Expected: UTF-8 with BOM
Actual: Windows Codepage 1252
cc @phenning
Issue Analytics
- State:
- Created 4 years ago
- Comments:15 (8 by maintainers)
Top Results From Across the Web
File encoding not preserved after saving in Notepad++
It can happen that a file is saved with a certain encoding, but upon reopening it in Notepad++ it is detected with another...
Read more >c# - UTF8 Character lost when written to file
I am suspecting that UTF8 Encoding is not the best thing to use but have yet to find a better working method. Any...
Read more >Solved: Create a .csv file that uses UTF-8 character encod...
Solved: Hello, as the title of the subject already suggests: I want to create a .csv file that uses UTF-8 character encoding. The...
Read more >Display problems caused by the UTF-8 BOM
Answer. If you are dealing with a file encoded in UTF-8, your display problems may be caused by the presence of a UTF-8...
Read more >How to test whether a file uses CRLF or LF without ...
I need to periodically run a command that ensures that some text files are kept in Linux mode. Unfortunately dos2unix always modifies the...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Thanks for fixing the issue @grinrag. Do you know what version of the .NET Core SDK this fix would appear in?
This looks like a bug when the first line of the processed file contains a conditional construct such as #if.
I just verified that either adding a blank line to the top of the file, or moving the #if to the next line as follows results in the encoding being preserved.
@ajaybhargavb This could be used as a a workaround in the template content until the root cause of underlying bug is found and fixed.