msbuildtasks
msbuildtasks copied to clipboard
TemplateFile task removes the byte order mark (BOM) from the generated file
TemplateFile task removes the byte order mark (BOM) from the generated file
MSBuild.Community.Tasks v1.4.0.56
<TemplateFile Template="C:\File.template" OutputFilename="C:\File.txt" Tokens="@(Tokens)" />
If File.template is UTF-8 encoded with a BOM, the generated file does not have a BOM.
I expected that if the template file has a BOM, then the generated file should also have a BOM.
Thank you.
Absolutely! That is especially crucial for me, when creating a .js files from the template that Windows expects to be UTF-8 with BOM.
I send UTF-16 XML with BOM to TemplateFile and it produces UTF-8 XML file without BOM. Obviously, a produced file is malformed XML since it header still states that:
<?xml version="1.0" encoding="utf-16"?>
Eventually XmlQuery fails with this error: There is no Unicode byte order mark. Cannot switch to Unicode.
I use such workaround:
<FileUpdate
Files="$(...)"
Regex="[uU][tT][fF]-16"
ReplacementText="utf-8"
/>
I agree. Something like "Copyright ©2018" will end up as "Copyright ©2018" unfortunately.