I have an asp.net MVC4 web application that uses style bundling for themes. I have a physical themes folder structure like so...
Themes\
_Base\
Theme1\
Theme2\
...\
Each themes folder has an arbitrary number of LESS files in it. In my BundleConfig.RegisterBundles
method, I have some logic that loops through each themes folder and creates a bundle for each. The bundling mechanism from System.Web.Optimization will watch for changes within the files and folders that are in existing bundles and flush the bundles cache, which works fine.
What I need, however, is a way for new theme folders (i.e. Theme3\
) to be copied into my Themes
root folder, and the application to recognize those without having to first restart it. I have tried creating a "dummy" bundle that references all files in every folder...
var changeTracking = new StyleBundle(BUNDLE_ROOT);
changeTracking.Transforms.Clear();
changeTracking.IncludeDirectory(THEME_ROOT, "*.less", true);
changeTracking.Transforms.Add(new LessTransform());
changeTracking.Transforms.Add(new CssMinify());
bundles.Add(changeTracking);
...but that doesn't seem to help. When I make Theme3\
, it doesn't trigger another call to BundleConfig.RegisterBundles
. I still have to do an IISRESET, recycle the application pool, etc. to get the new theme to be recognized.
Is there any way I can dynamically add bundles after Application_Start has occurred?