$ cat "

Adding LESS to your ASP.NET Application


Most web developers would probably agree that it can be frustrating working with CSS. CSS is all but DRY since the are no good ways to reuse stuff between classes, etc. This makes CSS somewhat of a maintenance nightmare, but fortunately other tools have appeared in the web development world to mitigate this problem. One such tool is LESS.

To make use off LESS in your ASP.NET application the easiest way is to install the dotLess] [link=http://www.nuget.org/packages/dotless/]nuget package. This adds references to the needed assembly and adds a bunch of stuff to your web.config to add a handler which compiles your LESS into CSS.

The Nuget package does all the heavy lifting, but you might have to tell IIS what to do when someone requests a .less file, by adding a MIME type configuration.

In the webserver section of you web.config add the following snippet:

<mimeMap fileExtension=".less" mimeType="text/css" />

Another thing to remember is that if you are using the built in publishing/deployment features of Visual Studio to deploy your application you need to set the Build Action to Content for all your .less files, or they will not be included in the deployment.

Written by Erik Öjebo 2013-12-28 13:39