Note
When PowerShell quietly corrupts your source files
Characters like ₦ and curly quotes turned into garbage after scripted file writes on Windows. Here is the cause, and a one-line fix that has held up since.
Tooling · Lessons from building
While building One Ocean I was writing files from PowerShell scripts and here-strings. Some files came out with mangled characters, such as ₦ where ₦ should be. The next build would fail, or worse, still pass and ship broken copy.
Cause
Windows PowerShell 5.1 does not write plain UTF-8 by default. Depending on the cmdlet you get UTF-16 or the system ANSI code page, and -Encoding UTF8 adds a byte-order mark. Tools that expect clean UTF-8 then misread the file.
Fix
Write through .NET with an explicit UTF-8 encoder that has the BOM turned off:
$utf8 = New-Object System.Text.UTF8Encoding $false
[System.IO.File]::WriteAllText($path, $content, $utf8)Related project
One Ocean