Cake Addin for globing files
C# PowerShell
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
src/Cake.FileSet
tests
tools
.gitattributes
.gitignore
Cake.FileSet.sln
LICENSE
README.md
build.cake
build.ps1
integration-test.ps1

README.md

Cake.FileSet

AddIn that adds filesets to Cake using Microsoft.Extensions.FileSystemGlobbing which allows for both include and exclude patterns to be specified.

cakebuild.net NuGet Version

Dependencies

  • Cake v0.27.0
  • Microsoft.Extensions.FileSystemGlobbing v2.0.1
  • NETStandard.Library v2.0 when using .NETStandard2.0 or NET471

Build / Tests

Running Build / Unit Tests

.\build.ps1 -Target Test

Builds and runs the unit tests using build.cake.

Running Integration Tests

.\integration-test.ps1

Runs the integrations tests for both net framework and net core.

If you update the framework versions, cake version, or the file globbing package you'll need to modify the cake files at tests\Cake.FileSet.IntegrationTests.

Globbing patterns

The Microsoft globbing library supports the following two wildcard characters; * and **:

*

Matches anything at the current folder level, or any filename, or any file extension. Matches are terminated by / and . characters in the file path.

**

Matches anything across multiple directory levels. Can be used to recursively match many files within a directory hierarchy.

Globbing pattern examples

directory/file.txt

Matches a specific file in a specific directory.

directory/*.txt

Matches all files with .txt extension in a specific directory.

directory/*/bower.json

Matches all bower.json files in directories exactly one level below the directory directory.

directory/**/*.txt

Matches all files with .txt extension found anywhere under the directory directory.

Additional usage

When finding files by patterns you can use ! to negate a pattern (exclude it).

Further Information

For more information on how Mircosoft's globbing works please see either their documentation or their source .

Including the AddIn

#addin "Cake.FileSet"
#addin "nuget:?package=Microsoft.Extensions.FileSystemGlobbing&version=2.0.1"

Addin Usage

#addin "Cake.FileSet"
#addin "nuget:?package=Microsoft.Extensions.FileSystemGlobbing&version=2.0.1"

...

Task("GetFileSet.BySettings")
    .Does(() =>
    {
        var settings = new FileSetSettings {
            Includes = new string[] { "/src/**/one.txt" },
            Excludes = new string[] { "/src/c/*.txt" },
            BasePath = "D:/code/git/Cake.FileSet",
            CaseSensitive = false
        };

        var result = GetFileSet(settings);

        foreach(FilePath item in result)
        {
            Information(item);
        }
    });

Task("GetFileSet.ByIncludes")
    .Does(() =>
    {
        var result = GetFileSet( 
            includes: new string[] { "/src/**/*.txt" },
            excludes: new string[] { "**/two.txt" },
            caseSensitive: false,
            basePath: "D:/code/git/Cake.FileSet"
        );

        foreach(FilePath item in result)
        {
            Information(item);
        }
    });

Task("GetFileSet.ByInclude")
    .Does(() =>
    {
        var result = GetFileSet(
            include: "/src/**/*.txt",
            excludes: new string[] { "**/two.txt" },
            caseSensitive: false,
            basePath: "D:/code/git/Cake.FileSet"
        );

        foreach(FilePath item in result)
        {
            Information(item);
        }
    });

Task("GetFileSet.ByPatterns")
    .Does(() =>
    {
        var result = GetFileSet(
            patterns: new string[] { "**/one.txt", "!**/two.txt" },
            caseSensitive: false,
            basePath: baseDirectory
        );

        foreach(FilePath item in result)
        {
            Information(item);
        }
    });

Direct Usage

#addin "Cake.FileSet"
#addin "nuget:?package=Microsoft.Extensions.FileSystemGlobbing&version=2.0.1

...

IEnumberable<FilePath> bySettings = FileSet.Find(new FileSetSettings {
    Includes = new string[] { "/src/**/one.txt" },
    Excludes = new string[] { "/src/c/*.txt" },
    BasePath = "D:/code/git/Cake.FileSet",
    CaseSensitive = false
});

IEnumberable<FilePath> byIncludes = FileSet.Find(
    includes: new string[] { "/src/**/one.txt" },
    excludes: new string[] { "/src/c/*.txt" },
    basePath: "D:/code/git/Cake.FileSet",
    caseSensitive: false
);

IEnumberable<FilePath> byInclude = FileSet.Find(
    include: "/src/**/one.txt",
    excludes: new string[] { "/src/c/*.txt" },
    basePath: "D:/code/git/Cake.FileSet",
    caseSensitive: false
);

IEnumberable<FilePath> byPatterns = FileSet.Find(
    patterns: new string[] { "**/one.txt", "!**/two.txt" },
    basePath: "D:/code/git/Cake.FileSet",
    caseSensitive: false
);

General Notes

This is an initial version and not tested thoroughly.

I've created this addin for use in my own scripts as I wasn't happy with the usage of the in built one therefore use at your own risk :)