简体   繁体   English

如何在.less文件上打开Visual Studio 2010 .css Intellisense

[英]How to turn on Visual Studio 2010 .css Intellisense on .less file

Does anyone know how to enable css intellisense in a non .css file extension? 知道如何在非.css文件扩展名中启用css intellisense吗? I have a .less file that is basically a .css file but visual studio will not use .css intellisense on the file. 我有一个基本上是.css文件的.less文件,但visual studio不会在文件上使用.css intellisense。

Try using the CSS Is Less extension for VS2010: 尝试使用VS Is10的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标记。

Visual Studio allows you to map custom extensions to the different editors by going to Tools->Options->Text Editor->File Extension. Visual Studio允许您通过转到工具 - >选项 - >文本编辑器 - >文件扩展名将自定义扩展映射到不同的编辑器。 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团队似乎忽略了编辑列表中的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. 可能的解决方法是将扩展名与Html编辑器关联,然后在文件顶部键入<html><head><style> ,在文件底部键入</style></head></html> This will give you CSS intellisense support between the sets of tags. 这将为您提供标签集之间的CSS intellisense支持。 You can then remove the HTML tags and the file association when your done editing. 然后,您可以在完成编辑后删除HTML标记和文件关联。

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. 然后你会得到语法高亮,不太好用,你不必在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'; 如果您使用单个文件来定义颜色等,则必须将其命名为“.less”并使用@import'exampledefs.less'导入每个.less.css文件中; statement within that file. 该文件中的声明。

I'm really enjoying MindscapeWebWorkbench . 我真的很喜欢MindscapeWebWorkbench It is a free plugin for VS 2010 to provide .less support. 它是VS 2010的免费插件,提供.less支持。 In addition the extension came with .Sass and Coffee script support! 此外,扩展附带.Sass和Coffee脚本支持!

Give a try! 试一下!

Ahh, Hanselman approves ;) 啊,汉塞尔曼批准 ;)

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 在文件的底部

I highly recommend using Crunch: http://crunchapp.net/ 我强烈推荐使用Crunch: http//crunchapp.net/

Visual Studio (Express included) allows you to open Less files with Crunch. Visual Studio(包含Express)允许您使用Crunch打开Less文件。 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. 是的,它不会在Visual Studio中打开它们,它会打开Crunch来编辑文件,但是仍然有很多理由使用Crunch。 The biggest reason is that Crunch will take your Less code and compile to a pure CSS file. 最大的原因是Crunch会将你的Less代码编译成一个纯CSS文件。 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. 好处是你不需要在你的网站中包含less.js脚本,这可以避免额外的开销,你可以编写更少的代码,就像在VS中双击你的less文件,编辑文件一样简单,然后在你的CSS样式表上“压缩”(或保存)它。 No need to touch the pure CSS generated by crunch. 无需触摸紧缩产生的纯CSS。

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

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

相关问题 如何在.less文件上打开Visual Studio 2008 .css Intellisense - How to turn on Visual Studio 2008 .css Intellisense on .less file 如何从Visual Studio智能感知中排除CSS文件? - How to exclude CSS file from Visual Studio intellisense? 在部分视图和内容页面中查看CSS Intellisense - Visual Studio 2010? - Viewing CSS Intellisense in partial views and Content pages - Visual Studio 2010? Visual Studio以我不想要的方式格式化我的CSS / LESS,如何将其关闭? - Visual Studio is formatting my CSS/LESS in the way I don't want, how to turn it off? 如何在Visual Studio 2015中的LESS文件中获取Intellisense - How to get Intellisense in LESS files in Visual Studio 2015 Visual Studio 2010不链接CSS文件 - Visual Studio 2010 Not Linking CSS File Visual Studio 2015 CSS Intellisense破碎 - Visual Studio 2015 CSS Intellisense Broken 用于 React 中样式 CSS 的 Visual Studio Code Intellisense? - Visual Studio Code Intellisense for style CSS in React? Visual Studio 2015 智能感知与 css 字体真棒 - Visual studio 2015 intellisense with css font awesome Visual Studio Express 2013 CSS Intellisense无法正常工作 - Visual Studio Express 2013 CSS Intellisense not working
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM