Documentation

File search

To when adding bundles to a BundleCollection, you can control which files are added. The Add methods are overloaded to accept an IFileSearch object.

Here's an example that excludes some files:

public class CassetteConfiguration : IConfiguration<BundleCollection>
{
    public void Configure(BundleCollection bundles)
    {
        bundles.AddPerSubDirectory<ScriptBundle>("Scripts", new FileSearch
        {
            Pattern = "*.js",
            Exclude = new Regex("ignore-me\\.js$")
        });
    }
}

Default file searches

There are default file searches defined for each type of bundle. A FileSearch object has three properties:

  • Pattern - A string that matches file names. For example, "*.js"
  • SearchOption - A System.IO.SearchOption that defines if the search should be restricted to the top level of a directory, or include all sub-directories as well. The default is to search all sub-directories.
  • Exclude - An optional Regex used to test if a found file path should be excluded.

Script bundles

File search propertyDefault
Pattern"*.js"
SearchOptionSearchOption.AllDirectories
Excludenew Regex("-vsdoc.js$")

Extra magic: When any {file}.js and {file}.min.js are found, Cassette will ignore the file.min.js and only include file.js. Likewise, given both {file}.debug.js and {file}.js, Cassette will pick {file}.debug.js.

The Cassette.CoffeeScript plug-in modifies the default pattern to include *.coffee files.

Stylesheet bundles

File search propertyDefault
Pattern"*.css"
SearchOptionSearchOption.AllDirectories
Excludenull

The Cassette.Less plug-in modifies the default pattern include *.less files.

The Cassette.Sass plug-in modifies the default pattern include *.sass and *.scss files.

HTML template bundles

File search propertyDefault
Pattern"*.htm;*.html"
SearchOptionSearchOption.AllDirectories
Excludenull

The Cassette.Hogan plug-in modifies the default pattern to include *.mustache, *.jst and *.tmpl files.

Globally modifying the file searches

To globally modify the default file searches, define a public class that implements IFileSearchModifier<T>.

For example:

public class ModifyScriptFileSearch : IFileSearchModifier<ScriptBundle>
{
    public void Modify(FileSearch fileSearch)
    {
        fileSearch.SearchOption = SearchOption.TopDirectoryOnly;
    }
}

Cassette will find this class and use it to modify the default file search of the particular bundle type.