FileBasedApp.Toolkit.CSharp 0.17.0-rc-01

This is a prerelease version of FileBasedApp.Toolkit.CSharp.
dotnet add package FileBasedApp.Toolkit.CSharp --version 0.17.0-rc-01
                    
NuGet\Install-Package FileBasedApp.Toolkit.CSharp -Version 0.17.0-rc-01
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="FileBasedApp.Toolkit.CSharp" Version="0.17.0-rc-01" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="FileBasedApp.Toolkit.CSharp" Version="0.17.0-rc-01" />
                    
Directory.Packages.props
<PackageReference Include="FileBasedApp.Toolkit.CSharp" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add FileBasedApp.Toolkit.CSharp --version 0.17.0-rc-01
                    
#r "nuget: FileBasedApp.Toolkit.CSharp, 0.17.0-rc-01"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package FileBasedApp.Toolkit.CSharp@0.17.0-rc-01
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=FileBasedApp.Toolkit.CSharp&version=0.17.0-rc-01&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=FileBasedApp.Toolkit.CSharp&version=0.17.0-rc-01&prerelease
                    
Install as a Cake Tool

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 IFileSystem injection for testable file reads
  • Includes both synchronous and asynchronous evaluation
  • Provides CsharpProjectAnalysis for loading and analysing C# projects via MSBuild/Roslyn workspaces
  • Provides CompilationExtensions for querying compilations — find type symbols, enumerate named types, and discover interface implementations
  • Provides CompilationWrapper with cached type symbol lookups
  • Provides RoslynExtensions for classifying ITypeSymbol as string-like, task-like, or enumerable
  • Provides FileEvaluationExtensions for convenient AbsolutePath-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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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