Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET MVC 4 bundle with wildcard in folder path

My team uses a custom NuGet package for installing jQuery UI, which puts the theme files into a directory structure like this:

  • Content
    • jquery-ui-1.10.3
      • images
      • jquery-ui.css
      • jquery-ui.min.css

I'm trying to use ASP.NET MVC 4 bundles to include this content in the BundleConfig class inside my application's App_Start folder like so:

bundles.Add( new StyleBundle( "~/bundles/css" )
                 .Include( "~/Content/normalize-{version}.css",
                           "~/Content/jquery-ui-{version}/jquery-ui.css",
                           "~/Content/Site.css" ) );

This throws an error when I run the site:

Directory does not exist.
Parameter name: directoryVirtualPath

I also tried:

bundles.Add( new StyleBundle( "~/bundles/css" )
                 .Include( "~/Content/normalize-{version}.css" )
                 .IncludeDirectory( "~/Content/jquery-ui-*", "*.css" )
                 .Include( "~/Content/Site.css" ) );

That doesn't work either (obviously). I can explicitly specify the version on the folder, but that defeats part of the benefit of using the bundle.

So how can I use a wildcard in the folder path?

like image 963
Big McLargeHuge Avatar asked Aug 21 '13 22:08

Big McLargeHuge


1 Answers

You could use the overloaded version of IncludeDirectory which searches subdirectories.

Suppose you have the following file:

\Root\Content\jquery-ui-1.10.3\jquery-ui.css

Use this code to find and add it:

.IncludeDirectory("~/Content", "jquery-ui.css", true)

This is useful because it will always find jquery-ui.css, regardless of where you put it.

The downside to this method is that it will search for and include all jquery-ui.css files that it finds, which could cause some bugs if you don't ensure that only one jquery-ui.css exists.

(Remember that searching for subdirectories will also still search the root directory i.e. ~/Content)

like image 126
Rowan Freeman Avatar answered Oct 10 '22 21:10

Rowan Freeman