msbuildtasks icon indicating copy to clipboard operation
msbuildtasks copied to clipboard

TemplateFile task removes the byte order mark (BOM) from the generated file

Open icnocop opened this issue 10 years ago • 3 comments

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.

icnocop avatar Jun 11 '14 04:06 icnocop

Absolutely! That is especially crucial for me, when creating a .js files from the template that Windows expects to be UTF-8 with BOM.

pke avatar Sep 03 '15 20:09 pke

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"
            />

mediawolf avatar Feb 28 '18 05:02 mediawolf

I agree. Something like "Copyright ©2018" will end up as "Copyright ©2018" unfortunately.

Shawn1874 avatar Mar 01 '18 01:03 Shawn1874