AddIn that adds filesets to Cake using Microsoft.Extensions.FileSystemGlobbing which allows for both include and exclude patterns to be specified.
- Cake v0.33.0
- Microsoft.Extensions.FileSystemGlobbing v2.2.0
- NETStandard.Library v2.0 when using .NETStandard2.0
.\build.ps1 -Target Test
Builds and runs the unit tests using build.cake
.
.\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.
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=2.2.0"
#addin "Cake.FileSet"
#addin "nuget:?package=Microsoft.Extensions.FileSystemGlobbing&version=2.2.0"
...
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=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
);
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 :)