在 Visual Studio 中删除隐藏的文件结束字符 (BOM)
我正在使用批处理文件来连接我的所有 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
我之前已经在各个项目中多次执行过此操作,但该项目使用 .NET,并且所有文件都在 Visual Studio 中进行编辑。
我遇到的问题是,每个文件末尾添加了一些神秘的隐藏字符,这些字符连接起来后,会导致生成的 css 无效。
126 BLOCKQUOTE, Q 第 119 行第 1 列出现词汇错误。 遭遇: ”?” (63),之后:“”??? /**** 左栏 ****/
所有单独的 CSS 文件都会经过验证,并且仅在单独文件加入时才会在组合文件中抛出错误。
I'm using a batch file to concatenate all my css files
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.
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.
126 BLOCKQUOTE, Q Lexical error at line 119, column 1. Encountered: "?" (63), after : "" ??? /**** 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是由于文件中的字节顺序标记 (BOM) 造成的。字节顺序标记用于 unicode 文件告诉处理器字节的顺序。您可以在这里阅读更多相关信息:
http://en.wikipedia.org/wiki/Byte_order_mark
问题是 Visual Studio 将这些标记添加到您的 css 文件中,当您通过串联组合它们时,BOM 最终会出现在文本中间,从而把事情搞砸。
当您转到“另存为”对话框时,可以展开“保存”按钮以查看“使用编码保存”选项。这将提示您使用不同的编码,并且我认为其中一个 Unicode 选项将省略 BOM(列表中的某个位置是没有签名的 UTF-8)。
我不知道如何将 Visual Studio 设置为默认使用特定编码。
为了解决这个问题,我创建了一个程序来连接符合 BOM 的文件。我使用它而不是复制或 unix cat。
The problem is because of the byte order mark (BOM) in your files. The byte order mark is for unicode files to tell the processor the order of the bytes. You can read more about it here:
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.
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).
I don't know how to set Visual Studio to use a specific encoding by default.
To skirt the issues I created a program to concatenate files that would respect the BOM. I use that rather than copy, or the unix cat.
您可能想使用 YUICompressor .NET,而不是自己编写脚本。
You probably want to use YUICompressor .NET, instead of scripting this yourself.
我编写了一个漂亮的小命令行程序,它组合了所有文件(即 css 等)在目录中并为您删除 BOM(字节顺序标记)。它大约有 5 行代码,并使用 cssmin.js 来为您处理缩小。还有一个示例,展示了它在 Visual Studio 构建后事件中的外观。检查一下哦
I wrote a nifty little command line program that combines all files (i.e. css, etc) in a directory and removes the BOM (byte order mark) for you. It's about 5 lines of code and uses cssmin.js to handle the minification for you. There's also an example of how it looks in a Visual Studio post build event. Check it o