Include all files in a folder in a single bundle

58,825

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));
Share:
58,825

Related videos on Youtube

Jordan Axe
Author by

Jordan Axe

Updated on July 16, 2022

Comments

  • Jordan Axe
    Jordan Axe almost 2 years

    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.

  • Shaiju T
    Shaiju T over 8 years
    can we order the files in the directory as done here ?
  • Shaiju T
    Shaiju T over 8 years
    this doesn't including .min files, is there a solution ? , cause i have .min and .js files in the folder
  • Zabavsky
    Zabavsky over 8 years
    @stom, min files are usually included by the bundles in the release mode.
  • Shaiju T
    Shaiju T over 8 years
    yes you are correct as mentioned here , i have changed the web.config to <compilation debug="false"> and in BundleConfig.cs added BundleTable.EnableOptimizations = true; thank you.
  • Michael
    Michael over 8 years
    @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. stackoverflow.com/questions/22612157/…