【问题标题】:asp mvc IIS7 less/sass empty fileasp mvc IIS7 less/sass 空文件
【发布时间】:2016-01-13 19:42:14
【问题描述】:

我正在尝试在我的新项目中使用 less。我已经安装了 dotLess 和 System.Web.Optimization.Less 包(如Yet Another "Add LESS to your ASP.NET MVC Project" Post 中所述),并且在本地一切正常。但是当我发布项目 IIS7 服务器响应空 css 文件 /Content/Main/site?v=

这是我的 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="ExtensionlessUrlHandler-Integrated-4.0" path="*." verb="*" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
    <add name="dotless" path="*.LESS" verb="*" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition=""/>
  </handlers>
</system.webServer>

<dotless minifyCss="false" cache="true" web="false" />

还有我的 BundleConfig.cs

bundles.Add(new LessBundle("~/Content/Main/site").Include("~/Content/Main/Site.less"));

当我将 css 扩展名附加到我的 Site.less 文件 (Site.less.css) 时,服务器会以内容 (/Content/Main/site?v=K-FFpFNtIXPUlQamnX3qHX_A5r7TM2xbAgcuEmpm3O41) 进行响应,但它的所有变量等仍然较少。

Bundle Transformer: Sass and SCSS也一样

我错过了什么?

【问题讨论】:

    标签: asp.net-mvc iis-7 less dotless


    【解决方案1】:

    如你所愿

    /Content/Main/site?v=K-FFpFNtIXPUlQamnX3qHX_A5r7TM2xbAgcuEmpm3O41

    那么这意味着捆绑工作正常。因此,Site.less 中可能存在导致问题的原因。需要注意的一件事是相对 url。例如,如果您的 css 中有一张图片

    .bacon {
        background-image: url(bacon.png);
    }
    

    捆绑包将使用来自捆绑包名称的~/Content/Main 来查找它。 (/site 很好,可以是任何东西,它只是包的名称)

    首先要尝试的是取出所有导入、图像等,看看它是否正确捆绑。你可以通过在你的包配置中启用优化来在你的本地开发版本上执行此操作。

    BundleTable.EnableOptimizations = true
    

    【讨论】:

    • 我已经删除了所有的,只留下了body{ font-family: Arial; },但仍然是空的site?v=
    【解决方案2】:

    解决此问题的另一种方法是删除对System.Web.Optimization.LessdotLess 的依赖,并使用免费的Visual Studio 扩展https://github.com/madskristensen/WebCompiler 将less 预编译为css(有或没有缩小)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-10
      • 2012-06-07
      • 1970-01-01
      • 1970-01-01
      • 2010-09-20
      • 1970-01-01
      • 2014-10-03
      相关资源
      最近更新 更多