2014-12-03 18 views
9

Sto cercando di utilizzare CssRwriteUrlTransform in uno dei miei pacchi in bundleconfig, ma continuo a ricevere un errore di argomento mancante, questo è quello che ho:ASP.NET MVC cssRewriteUrlTransform più argomenti

bundles.Add(new StyleBundle("~/Content/GipStyleCss").Include(
     new CssRewriteUrlTransform(), 
     "~/Content/GipStyles/all.css", 
     "~/Content/GipStyles/normalize.css", 
     "~/Content/GipStyles/reset.css", 
     "~/Content/GipStyles/style.css", 
)); 

questo è probabilmente sbagliato, ma non so dove aggiungere l'argomento CssRewriteUrlTransform con un include che ha più argomenti

risposta

23

non è possibile combinare due overload del metodo di Include:

public virtual Bundle Include(params string[] virtualPaths); 
public virtual Bundle Include(string virtualPath, params IItemTransform[] transforms); 

Se avete bisogno di CssRewriteUrlTransform su ciascuno dei file, provate questo:

bundles.Add(new StyleBundle("~/Content/GipStyleCss") 
    .Include("~/Content/GipStyles/all.css", new CssRewriteUrlTransform()) 
    .Include("~/Content/GipStyles/normalize.css", new CssRewriteUrlTransform()) 
    .Include("~/Content/GipStyles/reset.css", new CssRewriteUrlTransform()) 
    .Include("~/Content/GipStyles/style.css", new CssRewriteUrlTransform()) 
); 
+0

Vedo, grazie, ci proverò ora! –

7

Ho incontrato la stessa situazione e finito per creare un piccolo metodo di estensione:

public static class BundleExtensions { 

    /// <summary> 
    /// Applies the CssRewriteUrlTransform to every path in the array. 
    /// </summary>  
    public static Bundle IncludeWithCssRewriteUrlTransform(this Bundle bundle, params string[] virtualPaths) { 
     //Ensure we add CssRewriteUrlTransform to turn relative paths (to images, etc.) in the CSS files into absolute paths. 
     //Otherwise, you end up with 404s as the bundle paths will cause the relative paths to be off and not reach the static files. 

     if ((virtualPaths != null) && (virtualPaths.Any())) { 
      virtualPaths.ToList().ForEach(path => { 
       bundle.Include(path, new CssRewriteUrlTransform()); 
      }); 
     } 

     return bundle; 
    } 
} 

È quindi possibile chiamare così:

 bundles.Add(new StyleBundle("~/bundles/foo").IncludeWithCssRewriteUrlTransform(
      "~/content/foo1.css", 
      "~/content/foo2.css", 
      "~/content/foo3.css" 
     ));