FileBasedApp.Toolkit
0.20.0
dotnet add package FileBasedApp.Toolkit --version 0.20.0
NuGet\Install-Package FileBasedApp.Toolkit -Version 0.20.0
<PackageReference Include="FileBasedApp.Toolkit" Version="0.20.0" />
<PackageVersion Include="FileBasedApp.Toolkit" Version="0.20.0" />
<PackageReference Include="FileBasedApp.Toolkit" />
paket add FileBasedApp.Toolkit --version 0.20.0
#r "nuget: FileBasedApp.Toolkit, 0.20.0"
#:package FileBasedApp.Toolkit@0.20.0
#addin nuget:?package=FileBasedApp.Toolkit&version=0.20.0
#tool nuget:?package=FileBasedApp.Toolkit&version=0.20.0
FileBasedApp.Toolkit
A collection of opinionated helpers and extensions for building file-based applications in .NET.
Features
- Provides a
PathUtilclass for working with paths and validating string paths - Provides an IO class to provide methods and extension methods for
TruePathFindInFiles— filter files by stream predicate or regex (withByLine/AllTextstrategies)Replace— in-place file text transformationSafeDeleteDirectory— safely delete directories with optional exception handling
- Provides
StringExtensionswithStringJoin,IsNullOrWhitespace, andIsNullOrEmptyconvenience methods - Provides an extension of the
CommandSettingsfrom theSpectre.Console.Cliproviding validation of file and directory paths - Provides a
SimpleExecRunnerfluent builder for constructing and executing system commands via theSimpleExeclibrary, with support for secrets redaction andTruePathintegration - Includes the following libraries
TruePathSimpleExecSpectre.Console.CliTestableIO.System.IO.Abstractions.WrappersTruePath.TestableIO.System.IO
Example
Extended settings
The example below shows how to use the ExtendedCommandSettings class to validate file and directory paths.
using FileBasedApp.Toolkit;
using Spectre.Console;
using Spectre.Console.Cli;
using TruePath;
public class CustomCommandSettings : ExtendedCommandSettings
{
[CommandArgument(0, "<directory-path>")]
public string? Directory { get; set; }
[CommandOption("--filePath")]
public required string File { get; set; }
public AbsolutePath DirectoryPath { get; set; }
public AbsolutePath FilePath { get; set; }
protected override ValidationResult DoValidate()
{
// Evaluates the directory string.
DirectoryPath = TryGetDirectory(Directory,
allowEmpty: true,
shouldExist: true,
PredefinedRootPath.ExecutionFolder);
FilePath = TryGetFile(File, true, roots: [PathUtil.GetCurrentWorkingFolder(), PathUtil.GetExecutionFolder()]);
return base.DoValidate();
}
}
TruePath IO extensions
using System.IO.Abstractions;
using FileBasedApp.Toolkit;
var applicationData = Environment.SpecialFolder.ApplicationData.GetSpecialFolder();
applicationData.FindRequiredParent(x => x.FileName == "SomeValue");
var ancestors = applicationData.GetAncestors(true).ToList();
// Combining with TruePath.TestableIO.System.IO
// This was orignally part of the FileBased.Toolkit library but moved
// to it's own library
var newDirectory = applicationData / "NewDirectory";
newDirectory.CreateDirectory();
IFileSystem fileSystem = new FileSystem();
fileSystem.File.Create(newDirectory / "test.txt");
(newDirectory / "..").GetDirectories(fileSystem)
SimpleExecRunner
The SimpleExecRunner provides a fluent builder API on top of the SimpleExec library for constructing and executing system commands. It supports TruePath types (AbsolutePath, LocalPath) directly as arguments, and can redact secrets from echoed output.
using FileBasedApp.Toolkit.SimpleExec;
using TruePath;
// Basic command execution
await new SimpleExecRunner("dotnet")
.AddArgument("build")
.AddArgument("MyProject.csproj")
.RunAsync();
// Using AddArgumentPair for flag + value combinations
await new SimpleExecRunner("dotnet")
.AddArgument("pack")
.AddArgumentPair("-c", "Release")
.AddArgumentPair("-o", outputPath) // accepts AbsolutePath directly
.RunAsync();
// With secrets redaction — the API key value is replaced with "***" in echoed output
await new SimpleExecRunner("dotnet")
.AddArguments("nuget", "push")
.AddArgument(packagePath)
.AddArgumentPair("--source", "nuget.org")
.AddArgumentPair("--api-key", apiKey, isSecret: true)
.RunAsync();
// Reading command output
var (stdout, stderr) = await new SimpleExecRunner("dotnet")
.AddArgument("--version")
.ReadAsync();
// Working directory, environment variables, and custom exit code handling
await new SimpleExecRunner("git")
.AddArguments("status", "--porcelain")
.WithWorkingDirectory(repoRoot)
.WithConfigureEnvironment(env => env["GIT_TERMINAL_PROMPT"] = "0")
.WithExitCodeHandler(code => code is 0 or 1)
.RunAsync();
Key types:
SimpleExecRunner— the fluent builder. Create withnew SimpleExecRunner("command-name"), add arguments, then callRun(),RunAsync(), orReadAsync().ISimpleExecCommandWrapper— an interface wrappingSimpleExec.Commandto enable unit testing. The default implementation (SimpleExecCommand) delegates directly to the staticCommandclass.
Web URIs (AbsoluteWebUri / RelativeWebUri)
Strongly-typed, immutable wrappers around System.Uri for composing web URIs. Path segments, query strings, and fragments are represented as validated value objects (UriPathSegment, UriQueryString, UriFragment) and can be combined fluently via the / operator.
using FileBasedApp.Toolkit;
// Build an absolute URI fluently
var url = AbsoluteWebUri.Create("https://example.com")
/ UriPathSegment.From("first")
/ UriPathSegment.From("second")
/ UriQueryString.From("a=1&b=2")
/ UriFragment.From("Fragment");
// https://example.com/first/second?a=1&b=2#Fragment
Console.WriteLine(url);
// Or use method form
var api = AbsoluteWebUri.Create("https://example.com/api")
.AddPathSegment(UriPathSegment.From("users"))
.AddQueryPart("page", "1")
.WithFragment(UriFragment.From("top"));
// Replace the entire path with a single segment (preserves query/fragment)
var reset = AbsoluteWebUri.Create("https://example.com/old/path?q=1")
.WithPathSegment(UriPathSegment.From("new"));
// https://example.com/new?q=1
// Relative URIs work the same way
var relative = RelativeWebUri.Create("/search")
/ UriQueryString.From("q=hello");
Each operation returns a new instance, so the originals are never mutated. Invalid inputs (empty segments, illegal characters) throw at the value-object construction step via Vogen validation.
HTTP extensions
AbsoluteWebUriHttpExtensions adds a WithBaseAddress extension on HttpClient that accepts an IWebUri<TSelf>, and HttpResponseMessageExtensions adds ToJson<T> / ToRequiredJson<T> for deserializing response content via a source-generated JsonTypeInfo<T>. Both deserialization helpers call EnsureSuccessStatusCode first; ToRequiredJson additionally throws InvalidOperationException when deserialization yields null.
using System.Text.Json.Serialization;
using FileBasedApp.Toolkit;
[JsonSourceGenerationOptions(PropertyNamingPolicy = JsonKnownNamingPolicy.CamelCase)]
[JsonSerializable(typeof(Widget))]
internal partial class AppJsonContext : JsonSerializerContext { }
public record Widget(string Name, int Count);
var baseUri = AbsoluteWebUri.Create("https://example.com/api");
var httpClient = new HttpClient().WithBaseAddress(baseUri);
using var response = await httpClient.GetAsync("widgets?id=1");
var widget = await response.ToRequiredJson(AppJsonContext.Default.Widget);
Template
You can use the FileBasedApp.Toolkit.Template to easily create a new filebase app with FileBasedApp.Toolkit references added https://www.nuget.org/packages/FileBasedApp.Toolkit.Template/
Bugs or things missing
Feel free to create an issue or submit a pull request.
Credits
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- NuGet.Versioning (>= 7.3.0)
- SimpleExec (>= 13.0.0)
- Spectre.Console.Cli (>= 0.55.0)
- TestableIO.System.IO.Abstractions.Wrappers (>= 22.1.0)
- TruePath (>= 1.12.0)
- TruePath.TestableIO.System.IO (>= 0.16.0)
- Vogen (>= 8.0.5)
-
net8.0
- NuGet.Versioning (>= 7.3.0)
- SimpleExec (>= 13.0.0)
- Spectre.Console.Cli (>= 0.55.0)
- TestableIO.System.IO.Abstractions.Wrappers (>= 22.1.0)
- TruePath (>= 1.12.0)
- TruePath.TestableIO.System.IO (>= 0.16.0)
- Vogen (>= 8.0.5)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on FileBasedApp.Toolkit:
| Package | Downloads |
|---|---|
|
FileBasedApp.Toolkit.CSharp
Roslyn-based helpers for detecting and working with file-based .NET apps. |
|
|
FileBasedApp.Toolkit.Dotnet
Fluent builders and recipes for dotnet CLI commands (pack, nuget push, package search). |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.20.0 | 108 | 4/17/2026 |
| 0.20.0-rc-01 | 103 | 4/16/2026 |
| 0.19.1 | 90 | 4/8/2026 |
| 0.19.0 | 128 | 4/8/2026 |
| 0.19.0-rc-01 | 106 | 4/8/2026 |
| 0.18.0 | 130 | 4/5/2026 |
| 0.18.0-rc-01 | 100 | 4/5/2026 |
| 0.17.0 | 124 | 3/29/2026 |
| 0.17.0-rc-01 | 96 | 3/25/2026 |
| 0.16.0 | 142 | 3/15/2026 |
| 0.15.0 | 131 | 3/13/2026 |
| 0.15.0-rc-01 | 108 | 3/12/2026 |
| 0.15.0-dev-05 | 96 | 3/11/2026 |
| 0.15.0-dev-03 | 95 | 3/11/2026 |
| 0.15.0-dev-02 | 86 | 3/11/2026 |
| 0.15.0-dev-01 | 109 | 3/11/2026 |
| 0.14.0 | 124 | 3/10/2026 |
| 0.14.0-preview-02 | 92 | 3/10/2026 |
| 0.13.0 | 83 | 3/8/2026 |
- Upgraded Spectre.Console.Cli from 0.53.1 to 0.55.0
- Added `IWebUri<TSelf>` interface with `static abstract Create` using the self-referential generic pattern
- Added `AbstractUri<TSelf>` base class with shared immutable URI operations: `AddPathSegment`, `WithFragment`, `WithRawQuerystring`, `AddQueryPart`, `HasQuery`, and `HasFragments`
- Added `RelativeWebUri` — strongly-typed relative URI with path, query, and fragment manipulation, implementing `IParsable<RelativeWebUri>`
- Added `AbsoluteWebUri` — strongly-typed absolute URI with validation, path combining (`/` operator), implicit conversion to `Uri`, and `IParsable<AbsoluteWebUri>`
- Added Vogen-based value objects `UriPathSegment`, `UriFragment`, and `UriQueryString` with validation and input normalization
- Changed `AbstractUri.AddPathSegment`, `WithFragment`, and `WithRawQuerystring` to take the new value objects instead of `string` for stronger typing and built-in validation
- Added `/` (divide) operators on `AbstractUri<TSelf>` for `UriPathSegment`, `UriFragment`, and `UriQueryString`, enabling fluent URI composition via operator chaining
- Added `AbsoluteWebUri.WithRelativeUri` and `/` operators for `string` (auto-detects path segment vs fragment) and `RelativeWebUri` for combining absolute and relative URIs
- Added `AbsoluteWebUriHttpExtensions.WithBaseAddress` extension method on `HttpClient` for setting its base address from an `IWebUri<TSelf>`
- Added `AbstractUri.WithPathSegment` for replacing the entire path of a URI with a single segment while preserving query and fragment
- Added `HttpResponseMessageExtensions` with `ToJson<T>` and `ToRequiredJson<T>` for deserializing response content via a source-generated `JsonTypeInfo<T>`; both call `EnsureSuccessStatusCode` first, and `ToRequiredJson` throws `InvalidOperationException` when deserialization yields `null`