AddIn that adds filesets to Cake using Microsoft.Extensions.FileSystemGlobbing which allows for both include and exclude patterns to be specified.
- Cake v0.23.0
- Microsoft.Extensions.FileSystemGlobbing v1.1.1
- NETStandard.Library v1.6.1 when using .NETStandard1.6 or NET46
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.
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.
When finding files by patterns you can use !
to negate a pattern (exclude it).
For more information on how Mircosoft's globbing works please see either their documentation or their source .
#addin "Cake.FileSet"
#addin "nuget:?package=Microsoft.Extensions.FileSystemGlobbing&version=1.1.1"
#addin "Cake.FileSet"
#addin "nuget:?package=Microsoft.Extensions.FileSystemGlobbing&version=1.1.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);
}
});
#addin "Cake.FileSet"
#addin "nuget:?package=Microsoft.Extensions.FileSystemGlobbing&version=1.1.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
);
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 :)