6

I have a project in Visual Studio 2015 with Asp.Net MVC 5.

All my css and js files are referenced by bundle (BundleConfig class + @Styles, @Scripts in cshtml pages).

Now i'm considering to use a .less file, instead a css file.

So, how will I refer this file in bundle? And the most important, can bundle (or something else) automatically convert .less in .css, or I need to do it manually?

3
  • 1
    Did you see Web Compiler? Commented Oct 11, 2016 at 0:08
  • @Shyju, Web Compiler is awesome. Works perfectly. Can you make this comment in a answer, so I could make correct answer. Commented Oct 11, 2016 at 13:58
  • @JonnyPiazzi Done Commented Oct 11, 2016 at 14:33

1 Answer 1

14

You might consider using Mads Kristensen's Web Compiler visual studio extension. This works in your local development setup(VS) and MS builds!.

So basically you will use this extension to generate css files from your .LESS files. You can use these generated css files when you bundle it.

Once you install the extension, you can right click on the less file, select Web Compiler=> Compile file.

enter image description here

This will generate the css file from LESS file. It will also add a file called compilerconfig.json which is more like a settings file. You can do more settings like enabling the recompilation on pre/post build by right clicking on this file.

enter image description here

So for evey LESS file you do this, it will add an entry to the compilerconfig file JSON file.

[
  {
    "outputFile": "Content/MasterStyles.css",
    "inputFile": "Content/MasterStyles.less"
  },
  {
    "outputFile": "Content/AdminStyles.css",
    "inputFile": "Content/AdminStyles.less"
  }
]

Now in your Bundle config, you can use the 2 css files generated for bundling.

The extension also supports minifying the files. you can enable/disable by updating the settings json file.

Sign up to request clarification or add additional context in comments.

2 Comments

this is static extension, you can't use it runtime (for dynamic application this is only 50% of solution)
Here is the updated version of the extension for VS 2022+ referenced in this post: marketplace.visualstudio.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.