dotLess CSS with .NET 4.0 & MVC3 Setup

Very simple. Download dotLess.Core from here… http://www.dotlesscss.org/

Inside your MVC3 project, open the web.config (not the web.config inside your Views folder).

Find a section that looks like this, we want to add to the end of it.

    <pages>
      <namespaces>
        <add namespace="System.Web.Helpers" />
        <add namespace="System.Web.Mvc" />
        <add namespace="System.Web.Mvc.Ajax" />
        <add namespace="System.Web.Mvc.Html" />
        <add namespace="System.Web.Routing" />
        <add namespace="System.Web.WebPages"/>
      </namespaces>
    </pages>

Add these lines, after the closing pages tag.

    <httpHandlers>
      <add type="dotless.Core.LessCssHttpHandler,dotless.Core" path="*.css" verb="*" />
    </httpHandlers>

I have it set there, to process all CSS files. So I don’t have to mess around with .less files in VS 2010.

Now, put some test content into any of your projects CSS files…

@brand_color: #4D926F;
 
#header {
  color: @brand_color;
}
 
h2 {
  color: @brand_color;
}

Browse that file on your web server, and it should have executed correctly and your #header and h2 class have the relevant colour assigned to them.

Share

Leave a Comment


NOTE - You can use these HTML tags and attributes:
<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">