FileBasedApp.Toolkit.CSharp
0.17.0-rc-01
dotnet add package FileBasedApp.Toolkit.CSharp --version 0.17.0-rc-01
NuGet\Install-Package FileBasedApp.Toolkit.CSharp -Version 0.17.0-rc-01
<PackageReference Include="FileBasedApp.Toolkit.CSharp" Version="0.17.0-rc-01" />
<PackageVersion Include="FileBasedApp.Toolkit.CSharp" Version="0.17.0-rc-01" />
<PackageReference Include="FileBasedApp.Toolkit.CSharp" />
paket add FileBasedApp.Toolkit.CSharp --version 0.17.0-rc-01
#r "nuget: FileBasedApp.Toolkit.CSharp, 0.17.0-rc-01"
#:package FileBasedApp.Toolkit.CSharp@0.17.0-rc-01
#addin nuget:?package=FileBasedApp.Toolkit.CSharp&version=0.17.0-rc-01&prerelease
#tool nuget:?package=FileBasedApp.Toolkit.CSharp&version=0.17.0-rc-01&prerelease
FileBasedApp.Toolkit.CSharp
Roslyn-based helpers for detecting and working with file-based .NET apps.
Features
- Provides
FileBasedAppEvaluator— inspects C# source files using Roslyn to determine if they are file-based apps - Detects file-based directives in leading trivia:
#:package,#:property,#:sdk,#:project - Supports
IFileSysteminjection for testable file reads - Includes both synchronous and asynchronous evaluation
- Provides
CsharpProjectAnalysisfor loading and analysing C# projects via MSBuild/Roslyn workspaces - Provides
CompilationExtensionsfor querying compilations — find type symbols, enumerate named types, and discover interface implementations - Provides
CompilationWrapperwith cached type symbol lookups - Provides
RoslynExtensionsfor classifyingITypeSymbolas string-like, task-like, or enumerable - Provides
FileEvaluationExtensionsfor convenientAbsolutePath-based file-based app detection
Example
Detecting a file-based app
using FileBasedApp.Toolkit.CSharp;
using TruePath;
var evaluator = new FileBasedAppEvaluator();
var path = AbsolutePath.Create("/path/to/my-script.cs");
if (evaluator.IsFileBasedApp(path))
{
Console.WriteLine("This is a file-based app.");
}
A file is considered a file-based app when it is a top-level script (i.e. its first member is a global statement) and its leading trivia contains at least one recognised directive:
#:package FileBasedApp.Toolkit@0.17.0
#:property PublishAot=false
Console.WriteLine("Hello from a file-based app!");
Async evaluation
bool result = await evaluator.IsFileBasedAppAsync(path, cancellationToken: token);
Skipping the global statement check
By default, only top-level script files are considered. Pass requireGlobalStatement: false to evaluate any C# file regardless of structure:
bool result = evaluator.IsFileBasedApp(path, requireGlobalStatement: false);
Using a custom IFileSystem
using System.IO.Abstractions;
IFileSystem fileSystem = new MockFileSystem(); // e.g. from TestableIO
var evaluator = new FileBasedAppEvaluator(fileSystem);
Loading and analysing a C# project
using FileBasedApp.Toolkit.CSharp;
await using var analysis = new CsharpProjectAnalysis();
await analysis.Load("/path/to/MyProject.csproj");
// Access the Roslyn Compilation
var compilation = analysis.Compilation;
Finding interface implementations
using FileBasedApp.Toolkit.CSharp.Extensions;
// Find all types implementing a specific interface in the current assembly
var implementations = compilation.FindImplementationOfInterface(
"MyNamespace.IMyInterface", assemblyOnly: true);
foreach (var type in implementations)
{
Console.WriteLine(type.Name);
}
Type classification helpers
using FileBasedApp.Toolkit.CSharp.Extensions;
// Check if a type symbol is string-like (string or ReadOnlySpan<char>)
StringInfo info = typeSymbol.IsStringLike(compilation);
if (info.IsStringLike) { /* ... */ }
// Check if a type is Task-like (Task, Task<T>, ValueTask, ValueTask<T>)
bool isAsync = typeSymbol.IsTaskLike(compilation);
// Check if a type is enumerable and get the element type
EnumerableInfo enumInfo = typeSymbol.TryGetEnumerableElementType(compilation);
if (enumInfo.IsEnumerable)
{
Console.WriteLine($"Element type: {enumInfo.ElementType.Name}");
}
Bugs or things missing
Feel free to create an issue or submit a pull request.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- FileBasedApp.Toolkit (>= 0.17.0-rc-01)
- Microsoft.Build (>= 18.0.2)
- Microsoft.Build.Locator (>= 1.7.8)
- Microsoft.CodeAnalysis.CSharp (>= 5.3.0)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 5.3.0)
- Microsoft.CodeAnalysis.Workspaces.Common (>= 5.3.0)
- Microsoft.CodeAnalysis.Workspaces.MSBuild (>= 5.3.0)
- Roslynator.CSharp (>= 4.15.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 0.17.0-rc-01 | 31 | 3/25/2026 |
- Added FileBasedAppEvaluator: uses Roslyn to detect file-based apps by inspecting leading trivia for #:package, #:property, #:sdk, or #:project directives
- Added CsharpProjectLoader for loading a csharp project