ASP.NET Optimization Doesn't Turn LESS into CSS

I'm having difficulty converting LESS files to CSS using the .NET Framework Optimization Framework (to minimize and group).

I have a directory containing only LESS files.

I use the following code to combine them and convert to CSS:

var lessBundle = new Bundle("~/st-style-common-2") .IncludeDirectory("~/Admin/Resources/styles/", "*.less"); lessBundle.Transforms.Add(new LessTransform()); lessBundle.Transforms.Add(new CssMinify()); bundles.Add(lessBundle); 

I also used the LessTransform class, which is described in detail here .

When debug = "false", the files are converted to standard CSS and compiled into one, as expected.

However, when debug = "true", the files do not translate, leaving fuzzy URLs in the HTML that the browser does not understand, and IIS does not seem to have a handler.

I understand that I could create a handler that will serve these .less files, but I don’t think what I need. Does the LESS optimization platform optimize for CSS even during debugging?

+4
source share
3 answers

I did not find a solution, in fact, but I managed to get around this problem using the Web Essentials plugin , which automatically converts my LESS files to CSS (as well as a smaller version of CSS).

This allows me to work with LESS, save the file and automatically compile the CSS styling version, and then just reference the CSS versions, not the LESS version:

 bundles.Add(new StyleBundle("~/styles").Include( "~/Admin/Resources/styles/*.css")); 
+4
source

Step 2 in the tutorial that you talked about where you got the LessTransform class says you must install the countless NuGet package. When you do this using the Visual Studio Package Manager, a carefree handler will automatically register with your Web.config. It is also important that Web.config also has the following:

 <modules runAllManagedModulesForAllRequests="true"> 

Thus, everything will work automatically, and your development team can work with the project, even if they did not have installed websites. I don’t like to be dependent on any extension in order to be able to work with the project (although I like web resources!)

+2
source

The problem is that optimization is not performed by default with debug = true, since for smaller files you always want to optimize the work so that you can explicitly set this by setting in your BundleConfig.cs:

 BundleTable.Bundles.EnableOptimizations = true 
+1
source

Source: https://habr.com/ru/post/1447489/


All Articles