4

I am using asp.net mvc4 and the built in bundling and minification that is provided by MS using the System.Web.Optimization library (1.1.0) with a custom LessTransform using dotless. The site is hosted in IIS 7. My problem is that intermittently the bundle is empty on the website which causes the website to load all weird.

http://site/Content/surveycss?

What could cause this?

UPDATE

  1. I read that if the less compiler encounters an error it could result in an empty bundle. I've tested the less for errors and there are none.

  2. I discovered that there maybe an issue with the way that the bundle was configured to use the Content directory, so I changed it from:

        bundles.Add(new StyleBundle("~/Content/bootstrap")
            .Include(...));
    

to:

        bundles.Add(new StyleBundle("~/cssbundles/bootstrap")
            .Include(...));

After redeploying the application, it appeared to resolve the issue. However, it's happening again. The setup is a load balancer that with 2 IIS servers. Today, I logged onto server 1 and browsed the site via IIS and it's loading fine.

Logging onto server 2 and browsing the site via IIS gives the bundling issue.

Update 2

To test the thought that the resource might be in use. I tried deleting the less files that were part of the bundle that caused the issue. The less files were successfully deleted. Upon restoring the .less files, the issue went away when browsing directly to the server.

Update 3

This issue just started cropping up on the dev server which is not load balanced with a bundle that is not using dotless

    bundles.Add(new StyleBundle("~/cssbundles/bootstrap")
        .Include("~/Content/bootstrap/bootstrap.css"));

This was caused because of a nuget package upgrade and a file no longer being in the location it was referenced. I double checked all of the other bundles to make sure the files still existed where they were referenced and they do, so that's not the issue.

Update 4

Added logging to the dotless configuration and received this message:

06-12-2013 16:08:07.814,10.183.130.143,demo.app.com,/cssbundles/bundlecss?v=WN4weCPcGs3GJ_Hgsm2B7qNotYNgbrMS6xwEt8SWK6M1,user@email.com,"
directive block with unrecognised format on line 1:
   []: /beginning of file
  [1]: @v: WN4weCPcGs3GJ_Hgsm2B7qNotYNgbrMS6xwEt8SWK6M1;
       ^
  [2]: @import ""~/Content/variables.less"";",Error,""

Thoughts?

4

1 回答 1

2

发生这种确切情况 ( v=[no value]) 因为文件Build Action上的值.less被意外设置为None. 发生这种情况是因为文件以不寻常的方式添加到项目中,然后重命名为.less. 由于 VS.NET 最初并不知道文件类型,因此将其属性设置为Build Actionto none

确保.less文件的Build Action配置设置为Compile,从而允许实际文件包含在构建中。这也是为什么问题不会在本地发生,因为它会出现,但一旦部署它就会丢失。

于 2015-07-21T21:14:15.457 回答