public void AddFromJson(BundleCollection bundles) { try { var root = System.Web.Hosting.HostingEnvironment.MapPath("~"); var bundlesInfoFile = Path.Combine(root, _bundlesFile); if (!File.Exists(bundlesInfoFile)) { _logger.Warn($"Cannot register the Application's Bundles. File not found: {bundlesInfoFile}. Ignore this Warning if you do not have any Web Pages in your Application."); return; } var bundlesInfoContent = File.ReadAllText(bundlesInfoFile); if (string.IsNullOrWhiteSpace(bundlesInfoContent)) { _logger.Warn($"Cannot register the Application's Bundles. Found and empty file: {bundlesInfoFile}. Ignore this Warning if you do not have any Web Pages in your Application."); return; } var jsonBundles = Newtonsoft.Json.JsonConvert.DeserializeObject <Bundles>(bundlesInfoContent); if (jsonBundles == null) { _logger.Warn($"Deserialization of the JSON Bundles returned NULL. Ignore this Warning if you do not have any Web Pages in your Application."); return; } if ((jsonBundles.Scripts == null || jsonBundles.Scripts.Count == 0) && (jsonBundles.Styles == null || jsonBundles.Styles.Count == 0)) { _logger.Warn($"Found no Styles or Scripts in: {bundlesInfoFile}. Ignore this Warning if you do not have any Web Pages in your Application."); return; } foreach (var script in jsonBundles.Scripts) { if (script.Paths.Count == 0) { continue; } var bundle = new ScriptBundle(script.Name); foreach (var path in script.Paths) { bundle.Include(path); } bundles.Add(bundle.WithCustomTransformation(_applicationVersion, true)); } foreach (var style in jsonBundles.Styles) { if (style.Paths.Count == 0) { continue; } var bundle = new StyleBundle(style.Name); foreach (var path in style.Paths) { bundle.Include(path); } bundles.Add(bundle.WithCustomTransformation(_applicationVersion, false)); } } catch (System.Exception ex) { _logger.Error($"Caught a [{ex.GetType()}] Exception while Registering Bundles: {ex.Message}"); _logger.Error(ex.StackTrace); throw; } } //end AddFromJson()