¿Por qué ResolveBundleUrl no funciona para carpetas personalizadas? (MVC Beta 4)

From a brand-new ASP.NET MVC 4 Beta Web Application, I'm re-arranging my folders to match Rob Conery's VidPub.Web example

Specifically, this means that the final directory structure for content looks like this

VidPub.Web
 |
 ---Public
    |
    |---Images
          |--- *.png 
    |---javascripts
          |--- *.js 
    |---stylesheets
         |----themes
              |---base  
                  |--- images
                  |--- *.css
        |----site.css

However, when I change the following lines in _Layout.cshtml

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Content/css")" 
           rel="stylesheet" 
           type="text/css" />

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Content/themes/base/css")" 
           rel="stylesheet" 
           type="text/css" />

<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
             "~/Scripts/js")"></script>

a

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Public/stylesheets/css")"
           rel="stylesheet" 
           type="text/css" />

<link href="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Public/stylesheets/themes/base/css")" 
           rel="stylesheet" 
           type="text/css" />

<script src="@System.Web.Optimization.BundleTable.Bundles.ResolveBundleUrl(
           "~/Public/javascripts/js")"></script>

I end up with absolutely nothing in the resulting HTML.

<link rel="stylesheet" type="text/css" />
<link rel="stylesheet" type="text/css" />
<script></script>

Why isn't it picking up the files in their new locations?

preguntado el 10 de marzo de 12 a las 15:03

2 Respuestas

Debajo Application_Start in Global.asax.cs utilizado BundleTable.Bundles.EnableDefaultBundles(); en lugar de BundleTable.Bundles.RegisterTemplateBundles();

Si miras la fuente de RegisterTemplateBundles you can see that it actually only looks for (and adds) specific js and css files. EnableDefaultBundleson the other hand does pretty much the same as when you add you own bundles.

Respondido el 05 de Septiembre de 12 a las 11:09

WOW! Totally life saver... I think I need to add a comment in this post dotnet.learningtree.com/2012/03/26/… to let the author know about this. - Leniel Maccaferri

You can read more about this in his blog post: blog.degree.no/2012/03/… - Stian

Question: Why doesn't it work when you add all your css files to a folder in Content/Themes/default/css ? - Jacques

It appears you have to register your own bundle when using non-default directories. I added the following to Application_Start and it fixed the problem

var bundle = new Bundle("~/Public/stylesheets/css", new CssMinify());
bundle.AddDirectory("~/Public/stylesheets", "*.css", true);
BundleTable.Bundles.Add(bundle);

bundle = new Bundle("~/Public/javascripts/js", new JsMinify());
bundle.AddDirectory("~/Public/javascripts", "*.js", true);
BundleTable.Bundles.Add(bundle);

respondido 10 mar '12, 15:03

Con Microsoft.AspNet.Web.Optimization.1.0.0-beta2 tu reemplazas new Bundle(..., new CssMinify()) a StyleBundle y new Bundle(..., new JsMinify()) a ScriptBundle. - Douglas HM

Con Microsoft.AspNet.Web.Optimization.1.0.0-beta2 it seems like AddDirectory is no longer a supported method on Bundle. So what's the new fix? - feliz primero

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.