114

When using BundleConfig is it possible to include all files of a folder including all the files of the childfolders (and their childfolders etc.)?

I found .IncludeDirectory() but it seems to only include the files of the folder itself, not the files of the subfolders.

Liam
  • 27,717
  • 28
  • 128
  • 190
Jordan Axe
  • 3,823
  • 6
  • 20
  • 27

1 Answers1

229

Use the overload of IncludeDirectory method which accepts bool searchSubdirectories as third parameter.

MSDN:

searchSubdirectories - Specifies whether to recursively search subdirectories of directoryVirtualPath.

Example:

bundles.Add(new ScriptBundle("~/bundles/scripts")
    .IncludeDirectory("~/Scripts", "*.js", true));
SavoryBytes
  • 35,571
  • 4
  • 52
  • 61
Zabavsky
  • 13,340
  • 8
  • 54
  • 79
  • 2
    can we order the files in the directory as done [here](http://stackoverflow.com/a/11981271/2218697) ? – Shaiju T Jan 18 '16 at 08:12
  • 3
    this doesn't including `.min` files, is there a solution ? , cause i have `.min` and `.js` files in the folder – Shaiju T Jan 18 '16 at 09:48
  • 2
    @stom, min files are usually included by the bundles in the release mode. – Zabavsky Jan 18 '16 at 11:08
  • 1
    yes you are correct as mentioned [here](http://stackoverflow.com/a/22515066/2218697) , i have changed the `web.config` to `` and in `BundleConfig.cs` added `BundleTable.EnableOptimizations = true;` thank you. – Shaiju T Jan 18 '16 at 11:35
  • 4
    @Zabavsky, There is a bug in Web.Optimization version 1.1 in which your answer doesn't work, but updating to the latest version or downgrading to 1.0 will fix it. Might want to add that to your answer to save people some time. http://stackoverflow.com/questions/22612157/asp-net-mvc-5-sub-directory-bundling-issues/22613864#22613864 – Michael Jan 20 '16 at 19:02