This project has moved. For the latest updates, please go here.

Problem: LESS file imports are added to BundleResponse.Files collection

Nov 22, 2013 at 5:55 PM
Edited Nov 22, 2013 at 5:58 PM
First of all let me thank you for this great work. I finally managed to replace dotLess with BundleTransformer, everything works, except one thing, which leads to massive problems:

I use BundleTransformer in a multi-tenant environment, where different stylesheets must be served on a tenant base, because each tenant can manage their own sets of LESS variables in the database. I've overwritten Bundle.GetCacheKey() (among others) to vary cache keys by tenants successfully. When stylesheets for the first tenant are processed, everything works like a charm, but once a second tenant makes a request, the requested Bundle suddenly contains all imports in addition to my parent LESS files (in the sum I have 60 imports, pretty much ;-))

I suspect TransformerBase.ConfigureBundleResponse() to be responsible for this but am not sure. However, a quick look at the code reveals that all imports (dependencies) are pushed into Bundle.Files, which unfortunately makes this otherwise wonderful project unusable in my special environment.

Do you have a clue what I can do about this?
Nov 23, 2013 at 8:15 AM
Hello, Murat!

Currently the Microsoft ASP.NET Web Optimization Framework do not gives us opportunities to directly manage the cache dependencies of bundle, and therefore we can only add @imports (as well as other types of file dependencies) to the BundleResponse.Files property. In fact, the BundleResponse.Files property contains only references.

Actually, I don't quite understand how working your solution. Let me just say one, that the Bundle Transformer work with file system via the virtual path provider, which can be specified by using the BundleTable.VirtualPathProvider property. You need to write your own implementation of the VirtualPathProvider class.
Nov 23, 2013 at 4:11 PM
Edited Nov 23, 2013 at 4:13 PM
I already make heavy use of VirtualPathProvider (implemented my own to load LESS files from database and create custom CacheDependeny instances).

In the meantime I managed to clean out BundleResponse.Files by removing all LESS imports within my overridden Bundle.UpdateCache(). But one problem remains: Enable custom cache key creation for debug mode. I don't like the idea of implementing my own HttpHandler, this would lead to much redundant code.

If you could give me a hint about whether you plan to implement the issue, I would wait for it, otherwise I will implement a custom HttpHandler :-(

Thank you
Nov 23, 2013 at 4:29 PM
Edited Nov 23, 2013 at 5:21 PM
There are 2 variants:
  1. Using of the VirtualPathProvider.GetCacheKey method
  2. Creation of base classes CoffeeScriptAssetHandlerBase, LessAssetHandlerBase, SassAndScssAssetHandlerBase and TypeScriptAssetHandlerBase with possibility of overriding the GetCacheKey method
Which do you like better variant?
Nov 23, 2013 at 7:21 PM
The second option with the possibility of overriding GetCacheKey would absolutely be perfect :-)

Keep up the good work!
Nov 24, 2013 at 5:05 PM
Has implemented second option in the Bundle Transformer 1.8.12.
Nov 24, 2013 at 7:55 PM
Perfect :-) I'm going to drive an update tomorrow... Thank you very much!