Aray Karjauv
Aray Karjauv

Reputation: 2945

asp mvc IIS7 less/sass empty file

I'm trying to use less in my new project. I've installed dotLess and System.Web.Optimization.Less packeges (as described in Yet Another "Add LESS to your ASP.NET MVC Project" Post) and locally everything works fine. But when I publish project IIS7 server responds with empty css file /Content/Main/site?v=

Here is my web.config

...

<configSections>
  <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
</configSections>

<system.web>
  <httpHandlers>
  <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
</httpHandlers>
</system.web>

<system.webServer>
  <validation validateIntegratedModeConfiguration="false" />
  <handlers>
    <add name="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="dotless" path="*.LESS" verb="*" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition=""/>
  </handlers>
</system.webServer>

<dotless minifyCss="false" cache="true" web="false" />

And my BundleConfig.cs

bundles.Add(new LessBundle("~/Content/Main/site").Include("~/Content/Main/Site.less"));

When I append css extension to my Site.less file (Site.less.css) server responds with content (/Content/Main/site?v=K-FFpFNtIXPUlQamnX3qHX_A5r7TM2xbAgcuEmpm3O41) but it still pure less with all its variables and etc.

The same with Bundle Transformer: Sass and SCSS

What have I missed?

Upvotes: 1

Views: 718

Answers (2)

Konard
Konard

Reputation: 3014

Another way to solve this is to remove dependency on System.Web.Optimization.Less and dotLess and use free Visual Studio Extension https://github.com/madskristensen/WebCompiler for precompilation of less to css (with and without minification).

Upvotes: 0

Colin Bacon
Colin Bacon

Reputation: 15609

As you are getting

/Content/Main/site?v=K-FFpFNtIXPUlQamnX3qHX_A5r7TM2xbAgcuEmpm3O41

then this means that the bundling is working correctly. Therefore there is probably something in Site.less that is causing the problem. One thing to watch out for is relative urls. For example if you have an image in your css

.bacon {
    background-image: url(bacon.png);
}

The bundle will look for this with ~/Content/Main taken from the name of the bundle. (/site is fine and can be anything, it's just the name of the bundle)

The first thing to try is take out any imports, images etc and see if it bundles correctly. You can do this on your local dev build by enabling optimizations in the your bundle config.

BundleTable.EnableOptimizations = true

Upvotes: 1

Related Questions