问题
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
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.
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?
回答1:
This exact scenario occurred (v=[no value]
) because the Build Action
value on the .less
file was accidentally set to None
. This happened because the file was added to the project in an unusual way and then renamed to .less
. Since VS.NET didn't know originally the file type it set it's property for Build Action
to none
.
Make sure the .less
file has its Build Action
configuration set to Compile
, thus allowing the actual file is included in the build. This is also why the problem will not occur locally as it will be present, but once deployed it will be missing.
来源:https://stackoverflow.com/questions/20135051/empty-bundle-using-ms-bundling