From e83804900c0185c39260266ba8c165abda98317a Mon Sep 17 00:00:00 2001 From: Martin Ruiz Date: Tue, 7 Apr 2026 14:59:30 -0700 Subject: [PATCH] Remove BOM from localized file --- eng/Localize/RemoveUtf8Bom.ps1 | 20 ++++++++++++++++++++ eng/pipelines/templates/pipeline.yml | 1 + 2 files changed, 21 insertions(+) create mode 100644 eng/Localize/RemoveUtf8Bom.ps1 diff --git a/eng/Localize/RemoveUtf8Bom.ps1 b/eng/Localize/RemoveUtf8Bom.ps1 new file mode 100644 index 00000000000..d858d0d30fd --- /dev/null +++ b/eng/Localize/RemoveUtf8Bom.ps1 @@ -0,0 +1,20 @@ +# Removes UTF-8 BOM from localized files produced by the XLoc tool. +# Used via the xLocCustomPowerShellScript input in the OneLocBuild task. +# The XLocFileList environment variable is set by the task and contains +# the path to a text file listing all localized files to process. + +function RemoveUtf8Bom +{ + param( + [string]$FilePath + ) + + $encoding = New-Object -TypeName System.Text.UTF8Encoding -ArgumentList $false + $content = Get-Content -Path $FilePath -Encoding UTF8 + [System.IO.File]::WriteAllText($FilePath, $content -join "`n", $encoding) +} + +foreach ($locFile in (Get-Content -Path $env:XLocFileList)) +{ + RemoveUtf8Bom -FilePath $locFile +} diff --git a/eng/pipelines/templates/pipeline.yml b/eng/pipelines/templates/pipeline.yml index 48a74c7454f..48f4a5d8b81 100644 --- a/eng/pipelines/templates/pipeline.yml +++ b/eng/pipelines/templates/pipeline.yml @@ -67,6 +67,7 @@ stages: MirrorRepo: 'NuGet.Client' MirrorBranch: ${{ replace(variables['Build.SourceBranch'], 'refs/heads/', '') }} GitHubOrg: 'NuGet' + xLocCustomPowerShellScript: 'eng/Localize/RemoveUtf8Bom.ps1' - stage: Build_Insertable displayName: Build NuGet inserted into VS and .NET SDK