visual-studio 如何让 Visual Studio 停止“编译” .js 和 .css 文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2125455/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to make Visual Studio stop "compiling" .js and .css files
提问by Thomas Bonini
I use Visual Studio as my editor for .css and .js files.. It REALLY SUCKSespecially with .js files since it insists on indenting them in a very weird way, but I find it convenient that the first alt-tab is always the browser instead of another editor, and that ctrl-tab is always either the code file or the css/js.
我使用 Visual Studio 作为我的 .css 和 .js 文件编辑器。它真的很糟糕,尤其是 .js 文件,因为它坚持以一种非常奇怪的方式缩进它们,但我发现第一个 alt-tab 总是很方便浏览器而不是另一个编辑器,并且 ctrl-tab 始终是代码文件或 css/js。
Anyways, in all its radiant wisdom it decides to check them for syntax errors as well and every time I compile my project it gives several "errors" that push down the real errors of the compilation, so every time I make a syntax error in a code file I have to scroll down through all the js/css errors to see what's wrong.
无论如何,在它所有的光芒四射的智慧中,它决定检查它们是否有语法错误,每次我编译我的项目时,它都会给出几个“错误”,这些“错误”会降低编译的真正错误,所以每次我在一个代码文件我必须向下滚动所有 js/css 错误以查看问题所在。
Examples of such errors (that aren't really errors) are:
此类错误(不是真正的错误)的示例是:
Error 7 Validation (CSS 2.1): 'text-rendering' is not a known CSS property name. Error 8 Validation (CSS 2.1): 'opacity' is not a known CSS property name.
The situation also got much worse recently, since it now keeps parsing a .js file as a .css file for some reason, so I get errors such as:
最近情况也变得更糟,因为它现在出于某种原因不断将 .js 文件解析为 .css 文件,所以我收到如下错误:
Error 1 Unexpected character sequence. Expected a selector for the style rule. E:\Dev\anacletus\Static\set_focus.js 2 Error 2 Unexpected character sequence. Expected a property name for the " : " declaration. E:\Dev\anacletus\Static\set_focus.js 3 Error 3 Validation (CSS 2.1): 'set-focus' is not a known CSS property name. E:\Dev\anacletus\Static\set_focus.js 3
I even deleted that particular file from the solution (it's not there anymore anywhere), but it keeps parsing it anyway.
我什至从解决方案中删除了那个特定的文件(它不再存在于任何地方),但它仍然继续解析它。
In short, how can I disable this feature?
简而言之,如何禁用此功能?
回答by Dave Ward
Enter the options through
通过输入选项
Tools > Options
工具 > 选项
If it isn't checked, check the "Show all settings" box at the bottom of that window.
如果未选中,请选中该窗口底部的“显示所有设置”框。
In the tree to the left, choose:
在左侧的树中,选择:
Text Editor > CSS > CSS Specific
文本编辑器 > CSS > CSS 特定
Uncheck "Detect Errors". Then, choose:
取消选中“检测错误”。然后,选择:
Text Editor > JScript > Miscellaneous
文本编辑器 > JScript > 杂项
Uncheck "Show syntax errors".
取消选中“显示语法错误”。
You can also change how it indents each type of code too, in the various settings in those "Text Editor" sub-options.
您还可以在“文本编辑器”子选项的各种设置中更改每种类型代码的缩进方式。
回答by Matt
I know, this question is old, but I have an update (for Visual Studio 2010):
我知道,这个问题很旧,但我有一个更新(对于 Visual Studio 2010):
The accepted solution has a big disadvantage: It disables all syntax checking of CSS and JScript. If you still want to have meaningful warnings, you can do the following workaround. It will treat errors as warnings, and it will do css validation on css V3.0 level rather than on (old) css V2.1:
已接受的解决方案有一个很大的缺点:它禁用了 CSS 和 JScript 的所有语法检查。如果您仍然想要有意义的警告,您可以执行以下解决方法。它将错误视为警告,并将在 css V3.0 级别而不是(旧)css V2.1 级别上进行 css 验证:
- Close Visual Studio
- Download and install the web standards package for Visual Studio 2010 SP 1
- Open the path (on 32 bit machines, it is
Program Files)C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\1033\schemas\CSS
- Backup
CSS21.xmlfor safety reasons - Overwrite
CSS21.xmlby the fileCSS30.xml(in the same directory) - Open Visual Studio. In Text Editor settings, (re-)enable "Show syntax errors". Ensure you have checked "as warnings" too.
- 关闭 Visual Studio
- 下载并安装Visual Studio 2010 SP 1的Web 标准包
- 打开路径(在 32 位机器上,它是
Program Files)C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Packages\1033\schemas\CSS
CSS21.xml出于安全原因备份CSS21.xml由文件覆盖CSS30.xml(在同一目录中)- 打开 Visual Studio。在文本编辑器设置中,(重新)启用“显示语法错误”。确保您也已检查“作为警告”。
(Note that the Style Sheet toolbar only allows to enable CSS 3.0 checking for css files, not for HTML. Hence, this fix is needed if you want to keep syntax checking)
(请注意,样式表工具栏只允许启用 CSS 3.0 检查 css 文件,而不是 HTML。因此,如果您想保持语法检查,则需要此修复程序)

