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

CssVisual Studio-2010Visual StudioIntellisense

Css Problem Overview


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 Solutions


Solution 1 - Css

Try using the CSS Is Less extension for VS2010:

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.

Solution 2 - Css

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.

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.

Solution 3 - Css

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:

<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.

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.

Solution 4 - Css

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!

Give a try!

Ahh, Hanselman approves ;)

Solution 5 - Css

Late answer, but this is a hackish way to solve it in "pure" VS2010

#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

Solution 6 - Css

Solution 7 - Css

I highly recommend using 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.

Solution 8 - Css

Solution 9 - Css

I had to make add a MIME-type to my IIS server like this:

Extension: .less

MIME type: text/css

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaBetterGamerView Question on Stackoverflow
Solution 1 - CssLukeView Answer on Stackoverflow
Solution 2 - CssNick HView Answer on Stackoverflow
Solution 3 - CssDavidWainwrightView Answer on Stackoverflow
Solution 4 - CssCustodioView Answer on Stackoverflow
Solution 5 - CssErik KarlssonView Answer on Stackoverflow
Solution 6 - CssTom DudfieldView Answer on Stackoverflow
Solution 7 - CssskinneejoeView Answer on Stackoverflow
Solution 8 - CssCarlos Martinez TView Answer on Stackoverflow
Solution 9 - CssKristianBView Answer on Stackoverflow