I am trying to compile my .less
files into a css during runtime. But the dotless
library is failing to find the @import file.less
files.
All my files are in the same directory as the main less file.
This is my C# code:
var config = new DotlessConfiguration() {
MinifyOutput = true,
ImportAllFilesAsLess = true
};
string css = Less.Parse(less,config);
The main less file that i am trying to convert:
@import "font-awesome.less";
@fa-font-path: "/fonts";
@sco_green: #63b02e;
@sco_orange: #f18500;
@blue-deep:#00a2d1;
@white: #ffffff;
@active: #ffcb8b;
@gray: #999;
@gray-dark: #525252;
@gray-middle: #b8bcba;
@gray-light: #dbdbdb;
@gray-lighter: #efefef;
@gray-super-light: #f7f7f7;
@gray20:#333;
@gray94:#F0F0F0;
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="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
</handlers>
</system.webServer>
<dotless minifyCss="true" cache="true" web="false" disableParameters="true" />
Error Message:
How can i get it to work?
After going through almost every single search result on google, i found this:
Basically i need to set current working directory for dotless
to be able to find @import files:
so all i had to do in C# was:
string filePath = $"{_filePath}\\main.less";
string less = ReadFile(filePath);
var dotlessConfig = new dotless.Core.configuration.DotlessConfiguration();
Directory.SetCurrentDirectory(_filePath);
string css = Less.Parse(less,dotlessConfig);