title: Did Auto-Bundling/Minification Get Tossed in Final Release of MVC 4?
body: <p>According to an <a href="http://weblogs.asp.net/scottgu/archive/2011/11/27/new-bundling-and-minification-support-asp-net-4-5-series.aspx" rel="nofollow">article I read earlier by Scott Guthrie</a>, and a <a href="http://www.asp.net/web-forms/videos/aspnet-vnext/aspnet-vnext-videos-bundling-and-minification" rel="nofollow">video posted by Mads Kristensen</a>, I should be able to auto-bundle/minify in ASP.net MVC 4 by replacing this:</p>
  
  <pre><code>&lt;link href="Styles/reset.css" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="Styles/normalize.css" rel="stylesheet" type="text/css" /&gt;
  &lt;link href="Styles/styles.css" rel="stylesheet" type="text/css" /&gt;
  
  &lt;script src="Scripts/jquery-1.8.0.min.js" type="text/javascript"&gt;&lt;/script&gt;
  &lt;script src="Scripts/jquery-validation.min.js" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>With this:</p>
  
  <pre><code>&lt;link href="Styles/css" rel="stylesheet" type="text/css" /&gt;
  
  &lt;script src="Scripts/js" type="text/javascript"&gt;&lt;/script&gt;
  </code></pre>
  
  <p>I've tried targeting both .Net 4.0 and 4.5 and it doesn't seem to make a difference. I get 404 errors and the link and script tags are never directed at the bundled resources.</p>
  
  <p>Did this feature get dropped from the final version?</p>
  
  <p>I'd like to utilize this feature for "Themes".</p>
  
  <hr>
  
  <p>This is how I ended up implementing. Hopefully it makes sense...</p>
  
  <pre><code> /// &lt;summary&gt;
   /// Render stylesheets HTML for the given theme. Utilizes System.Web.Optimization for bundling and minification
   /// &lt;/summary&gt;
   /// &lt;param name="themeName"&gt;Name of theme&lt;/param&gt;
   /// &lt;returns&gt;HtmlString containing link elements&lt;/returns&gt;
   public static IHtmlString RenderThemeStyles(string themeName)
   {
       IHtmlString retValue = null;
  
       // If no theme name is passed, return null
       if (!themeName.HasValue())
           return retValue;
  
       var ctxt = HttpContext.Current;
       string themePath = "~/Themes/" + themeName;
       string themeKey = themePath + "/css";
  
       if (ctxt.Cache[themeKey] != null)
           return (IHtmlString)ctxt.Cache[themeKey];
  
       // Check to see if the theme directory exists. Throw error if it does not
       string themeSysPath = HttpContext.Current.Server.MapPath(themePath);
       DirectoryInfo themeDir = new DirectoryInfo(themeSysPath);
       if (!themeDir.Exists)
           throw new ApplicationException(string.Format("Theme directory \"{0}\" does not exist", themePath));
  
       // Remove the old bundle if it already exists
       var old_bundle = BundleTable.Bundles.FirstOrDefault(b =&gt; b.Path == themeKey);
       if (old_bundle != null)
           BundleTable.Bundles.Remove(old_bundle);
  
       if (themeDir.GetFiles("*.css").Length &gt; 0)
       {
           // If there are css files, add them to the bundler and save the rendered output to cache
           Bundle styles = new StyleBundle(themeKey).IncludeDirectory(themePath, "*.css");
           BundleTable.Bundles.Add(styles);
           retValue = Styles.Render(themeKey);
           ctxt.Cache.Insert(themeKey, retValue, new System.Web.Caching.CacheDependency(themeSysPath));
       }
       else
       {
           // If there are no css files, save empty string to cache
           ctxt.Cache.Insert(themeKey, new HtmlString(string.Empty), new System.Web.Caching.CacheDependency(themeSysPath));
       }
  
       return retValue;
   }
  </code></pre>