您正在导入一个无法找到的以 .less 结尾的文件

You are importing a file ending in .less that cannot be found

我正在尝试在运行时将我的 .less 文件编译成 css。但是 dotless 库找不到 @import file.less 文件。

我的所有文件都在与主要 less 文件相同的目录中。

这是我的 C# 代码:

    var config = new DotlessConfiguration() {
         MinifyOutput = true,
         ImportAllFilesAsLess = true
    };
    string css = Less.Parse(less,config);

我正在尝试转换的主要 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;

网络配置:

<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" />

错误信息:

我怎样才能让它工作?

在浏览 google 上的几乎所有搜索结果后,我发现 this:

基本上我需要为dotless设置当前工作目录才能找到@import文件:

所以我在 C# 中要做的就是:

    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);