My team uses a custom NuGet package for installing jQuery UI, which puts the theme files into a directory structure like this:
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?
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With