Dmitri Nesteruk
Dmitri Nesteruk

Reputation: 23789

How to ensure all VS code files are in UTF-8?

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!

Upvotes: 0

Views: 1287

Answers (1)

head_thrash
head_thrash

Reputation: 1711

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 $_ }

Upvotes: 1

Related Questions