简体   繁体   English

删除visual studio中的隐藏文件结束字符(BOM)

[英]Removing hidden file end characters (BOM) in visual studio

I'm using a batch file to concatenate all my css files 我正在使用批处理文件来连接我的所有css文件

copy /b reset.css+action-plan.css+buttons.css+behaviours.css+footer.css+forms.css+header.css+home.css+layout.css+lightbox.css+print.css+questionnaire.css+typography.css+you-told-us.css main.css

I've done this numerous times before on various projects, but this project uses .NET and the files are all being edited in visual studio. 我之前已经在各种项目上做了很多次,但是这个项目使用.NET,所有文件都在visual studio中编辑。

The problem I have is that there are some mysterious hidden characters being added at the end of each file, which, when concatenated, causes the resulting css to be invalid. 我遇到的问题是在每个文件的末尾添加了一些神秘的隐藏字符,当连接时,会导致生成的css无效。

 126 BLOCKQUOTE, Q Lexical error at line 119, column 1. 126 BLOCKQUOTE,Q第119行第1列的词汇错误。\n Encountered: "?" 遇到:“?” (63), after : "" ??? (63),之后:“”??? /**** left column ****/ / ****左栏**** / 

All the individual CSS files validate and the errors are only thrown in the combined file at teh points were the individual files join. 所有单独的CSS文件都会验证,并且只有单个文件加入时才会在组合文件中抛出错误。

The problem is because of the byte order mark (BOM) in your files. 问题是因为文件中的字节顺序标记(BOM)。 The byte order mark is for unicode files to tell the processor the order of the bytes. 字节顺序标记用于unicode文件,以告诉处理器字节的顺序。 You can read more about it here: 你可以在这里读更多关于它的内容:

http://en.wikipedia.org/wiki/Byte_order_mark http://en.wikipedia.org/wiki/Byte_order_mark

The problem is that Visual Studio is adding those marks to your css file and when you combine them by concatenation, BOMs are ending up in the middle of the text, screwing things up. 问题是Visual Studio正在将这些标记添加到您的css文件中,当您通过连接将它们组合在一起时,BOM会在文本的中间结束,从而搞砸了。

When you go to the Save As dialog, you can expand the Save button to see the 'Save with Encoding' option. 当您转到“另存为”对话框时,可以展开“保存”按钮以查看“使用编码保存”选项。 This will prompt you for a different encoding, and I think one of the Unicode options will leave out the BOM (somewhere in the list is UTF-8 without signature). 这将提示您输入不同的编码,我认为其中一个Unicode选项将遗漏BOM(列表中的某个位置是UTF-8,没有签名)。

I don't know how to set Visual Studio to use a specific encoding by default. 我不知道默认情况下如何设置Visual Studio使用特定的编码。

To skirt the issues I created a program to concatenate files that would respect the BOM. 为了解决问题,我创建了一个程序来连接符合BOM的文件。 I use that rather than copy, or the unix cat. 我使用它而不是复制,或使用unix cat。

您可能希望使用YUICompressor .NET ,而不是自己编写脚本。

I wrote a nifty little command line program that combines all files (ie css, etc) in a directory and removes the BOM (byte order mark) for you. 我编写了一个漂亮的小命令行程序 ,它将所有文件(即css等)组合在一个目录中,并为您删除BOM(字节顺序标记)。 It's about 5 lines of code and uses cssmin.js to handle the minification for you. 这是大约5行代码,并使用cssmin.js来处理缩小。 There's also an example of how it looks in a Visual Studio post build event. 还有一个示例,说明它在Visual Studio后期构建事件中的外观。 Check it o 检查o

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM