如何在 .less 文件上打开 Visual Studio 2010 .css Intellisense
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4973604/
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 turn on Visual Studio 2010 .css Intellisense on .less file
提问by aBetterGamer
Does anyone know how to enable css intellisense in a non .css file extension? I have a .less file that is basically a .css file but visual studio will not use .css intellisense on the file.
有谁知道如何在非 .css 文件扩展名中启用 css 智能感知?我有一个 .less 文件,它基本上是一个 .css 文件,但 Visual Studio 不会在该文件上使用 .css 智能感知。
采纳答案by Luke
Try using the CSS Is Less extension for VS2010:
尝试使用 VS2010 的 CSS Is Less 扩展:
http://visualstudiogallery.msdn.microsoft.com/dd5635b0-3c70-484f-abcb-cbdcabaa9923
http://visualstudiogallery.msdn.microsoft.com/dd5635b0-3c70-484f-abcb-cbdcabaa9923
Forces .LESS files to open in the CSS editor, without having to change settings or adding HTML tags to your LESS file.
强制 .LESS 文件在 CSS 编辑器中打开,而无需更改设置或向 LESS 文件添加 HTML 标签。
回答by Nick H
Visual Studio allows you to map custom extensions to the different editors by going to Tools->Options->Text Editor->File Extension. You simply supply the custom extension and select the editor you wish to associate it with. Sadly, the Visual Studio team has seemed to overlook the CSS editor in the list of editors.
Visual Studio 允许您通过转到工具->选项->文本编辑器->文件扩展名将自定义扩展名映射到不同的编辑器。您只需提供自定义扩展并选择您希望与之关联的编辑器。遗憾的是,Visual Studio 团队似乎忽略了编辑器列表中的 CSS 编辑器。
A possible work around is to associate the extension with the Html Editor and then type <html><head><style>
in the top of the file and </style></head></html>
in the bottom of the file. This will give you CSS intellisense support between the sets of tags. You can then remove the HTML tags and the file association when your done editing.
一种可能的解决方法是将扩展名与 Html 编辑器相关联,然后<html><head><style>
在文件顶部和文件</style></head></html>
底部键入。这将为您提供标签集之间的 CSS 智能感知支持。然后,您可以在完成编辑后删除 HTML 标记和文件关联。
回答by DavidWainwright
Another alternative is to name your files '.less.css', then change any references to them in either your master page or your main css file (the one that loads all the other css files with @import statements), then configure the less handler as follows in the 'handlers' section of your Web.Config file:
另一种选择是将文件命名为“.less.css”,然后在母版页或主 css 文件(使用 @import 语句加载所有其他 css 文件的文件)中更改对它们的任何引用,然后配置 less处理程序在您的 Web.Config 文件的“处理程序”部分中如下所示:
<add name="LessCssHandler" type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.LESS.CSS" verb="*" />
You then get syntax highlighting, less works fine and you've not had to set up new file extensions in vs, load any vs addins, etc, which is handy if you have a team of more than 1 developer.
然后你会得到语法高亮,less 工作正常,你不必在 vs 中设置新的文件扩展名,加载任何 vs 插件等,如果你的团队超过 1 个开发人员,这很方便。
If you use a single file to define colours etc, it will have to be named '.less' and imported into each .less.css file with an @import 'exampledefs.less'; statement within that file.
如果您使用单个文件来定义颜色等,则必须将其命名为 '.less' 并使用 @import 'exampledefs.less' 导入到每个 .less.css 文件中;该文件中的语句。
回答by Custodio
I'm really enjoying MindscapeWebWorkbench. It is a free plugin for VS 2010 to provide .less support. In addition the extension came with .Sass and Coffee script support!
我真的很喜欢MindscapeWebWorkbench。它是 VS 2010 的免费插件,提供 .less 支持。此外,扩展还带有 .Sass 和 Coffee 脚本支持!
Give a try!
试一下!
Ahh, Hanselman approves;)
啊,汉塞尔曼同意了;)
回答by Erik Karlsson
Late answer, but this is a hackish way to solve it in "pure" VS2010
迟到的答案,但这是在“纯”VS2010中解决它的一种hackish方法
#if DEBUG
<html><head><style>
#endif
in the top of the file and
在文件的顶部和
#if DEBUG
</style></head></html>
#endif
in the bottom of the file
在文件底部
回答by Tom Dudfield
This extension provides full Intellisense
此扩展提供完整的智能感知
http://visualstudiogallery.msdn.microsoft.com/e646c6ec-87a7-45ea-81e8-d655a3d3e73e
http://visualstudiogallery.msdn.microsoft.com/e646c6ec-87a7-45ea-81e8-d655a3d3e73e
回答by skinneejoe
I highly recommend using Crunch: http://crunchapp.net/
我强烈推荐使用 Crunch:http: //crunchapp.net/
Visual Studio (Express included) allows you to open Less files with Crunch. True it doesn't open them in Visual Studio, it opens Crunch to edit the file, but there are many reasons to use Crunch anyways. The biggest reason is that Crunch will take your Less code and compile to a pure CSS file. The benefits are that you don't need to include the less.js script in your website, which avoids extra overhead, you can write Less code, and it's as simple as double-clicking your less file in VS, editing the file, then "crunching" (or saving) it over your CSS stylesheet. No need to touch the pure CSS generated by crunch.
Visual Studio(包括 Express)允许您使用 Crunch 打开 Less 文件。确实,它不会在 Visual Studio 中打开它们,而是打开 Crunch 来编辑文件,但是无论如何使用 Crunch 的原因有很多。最大的原因是 Crunch 将把你的 Less 代码编译成一个纯 CSS 文件。好处是你不需要在你的网站中包含less.js脚本,避免了额外的开销,你可以编写Less代码,就像在VS中双击你的less文件,编辑文件一样简单,然后在 CSS 样式表上“处理”(或保存)它。无需接触 crunch 生成的纯 CSS。
回答by Carlos Martinez T
Nobody has mentioned Web Essentials 2012:
没有人提到过 Web Essentials 2012:
http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6
http://visualstudiogallery.msdn.microsoft.com/07d54d12-7133-4e15-becb-6f451ea3bea6
回答by KristianB
I had to make add a MIME-type to my IIS server like this:
我必须像这样向我的 IIS 服务器添加 MIME 类型:
Extension: .less
延期: .less
MIME type: text/css
MIME 类型: text/css