C# 您正在导入一个以.less结尾的文件,但找不到该文件
我试图在运行时将C# 您正在导入一个以.less结尾的文件,但找不到该文件,c#,dotless,C#,Dotless,我试图在运行时将.less文件编译成css。但是dotless库找不到@import file.less文件 我的所有文件都与主less文件位于同一目录中 这是我的C#代码: 我尝试转换的主less文件: @import "font-awesome.less"; @fa-font-path: "/fonts"; @sco_green: #63b02e; @sco_orange: #f18500; @blue-deep:#00a2d1; @white: #ffffff; @active: #
.less
文件编译成css。但是dotless
库找不到@import file.less
文件
我的所有文件都与主less文件位于同一目录中
这是我的C#代码:
我尝试转换的主less文件:
@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配置:
<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" />
我怎样才能让它工作呢?在浏览了谷歌上几乎所有的搜索结果后,我发现
基本上,我需要为dotless
设置当前工作目录,以便能够找到@import文件:
所以我在C#所要做的就是:
显示真实代码,否则很难猜测。我添加了.less文件内容。我还应该提供什么代码?
<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" />
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);