0

Is there a way to ensure all code files in my Visual Studio solution are encoded in UTF-8? I'd prefer this done automatically rather than by hand. Thanks!

Dmitri Nesteruk
  • 23,067
  • 22
  • 97
  • 166

1 Answers1

1

Short answer - you can't do this in one automatic action, because there is no deterministic way of knowing that file has other encoding than UTF-8. Surely, you can say a lot for BOM, but there are cases in which file is in UTF but has no BOM at all.

Best way IMO is to always resave new file as UTF-8 (I assume you are using R# and experience results of RSRP-291502 bug).

You still can try semi-automatic action (see script below) and then check manually for corrupted results.

Powershell :

gci . -include *.cs -recurse | ForEach-Object { (Get-Content $_) | Out-File -Encoding UTF8 $_ }
head_thrash
  • 1,623
  • 1
  • 21
  • 26