Forlet.AssemblyScanner
1.0.1
There is a newer version of this package available.
See the version list below for details.
See the version list below for details.
dotnet add package Forlet.AssemblyScanner --version 1.0.1
NuGet\Install-Package Forlet.AssemblyScanner -Version 1.0.1
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="Forlet.AssemblyScanner" Version="1.0.1" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Forlet.AssemblyScanner" Version="1.0.1" />
<PackageReference Include="Forlet.AssemblyScanner" />
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 Forlet.AssemblyScanner --version 1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: Forlet.AssemblyScanner, 1.0.1"
#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 Forlet.AssemblyScanner@1.0.1
#: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=Forlet.AssemblyScanner&version=1.0.1
#tool nuget:?package=Forlet.AssemblyScanner&version=1.0.1
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
Forlet.AssemblyScanner
A lightweight .NET assembly scanner for discovering types by interface implementation or base class inheritance. Uses MetadataLoadContext for safe metadata-only inspection with smart build detection.
Perfect for code generation tools, CLI scaffolders, build-time analyzers, and development tooling.
Features
- Smart Build Detection — Automatically builds projects when DLLs are missing or stale
- Metadata-Only Loading — Safe, non-executing inspection via
MetadataLoadContext - Performance Optimized — Configurable path scanning for large projects
- Generic Type Support — Full support using backtick notation (
ICommand1`) - Flexible Filtering — Include/exclude abstract classes, structs, nested types, non-public types
Installation
dotnet add package Forlet.AssemblyScanner
Quick Start
using Forlet.AssemblyScanner;
// Resolve and build if needed
var result = await ProjectDllResolver.PrepareAssemblyAsync("/path/to/MyProject.csproj");
// Scan for types
using var scanner = new MetadataScanner(result.DllPath);
var commands = scanner.FindTypesImplementing("ICommand");
foreach (var type in commands)
{
Console.WriteLine($"Found: {type.FullName}");
}
Check if a Type Exists
var result = await ProjectDllResolver.PrepareAssemblyAsync(csprojPath);
using var scanner = new MetadataScanner(result.DllPath);
// Early-exit optimization — stops at first match
var user = scanner.FindTypeByNameDerivedFrom("User", "BaseEntity");
if (user != null)
{
Console.WriteLine("User entity already exists");
}
Generic Types
Use backtick notation for generic types:
// Find ICommand and ICommand<T>
var commands = scanner.FindTypesImplementing(new[] { "ICommand", "ICommand`1" });
// Find IHandler<TRequest, TResponse>
var handlers = scanner.FindTypesImplementing("IHandler`2");
Configuration
Build Options
var result = await ProjectDllResolver.PrepareAssemblyAsync(
csprojPath,
new ProjectDllResolverOptions
{
BuildStrategy = BuildOptions.AutoBuild, // AutoBuild | NoBuild | AlwaysBuild
Configuration = "Debug",
PathsToCheck = new[] { "Commands", "Handlers" }, // Faster staleness checks
OnBuildStart = () => Console.WriteLine("Building...")
}
);
| Strategy | Behavior |
|---|---|
AutoBuild |
Builds if DLL is missing or stale (default) |
NoBuild |
Throws if DLL is missing or stale |
AlwaysBuild |
Always rebuilds before scanning |
Scan Options
var types = scanner.FindTypesImplementing(
"IHandler",
new ScanOptions
{
MatchFullName = false, // Match simple name (default) or full namespace
IncludeAbstract = false, // Include abstract classes
IncludeNonPublic = false, // Include internal/private types
IncludeStructs = false, // Include struct implementations
IncludeNestedTypes = false // Include nested types
}
);
How It Works
- Resolve — Parses
.csprojfor target framework, output path, and assembly name - Stale Check — Compares DLL timestamp against source files
- Build — Runs
dotnet buildif needed (when usingAutoBuild) - Load — Creates
MetadataLoadContextwith runtime assemblies from.deps.json - Scan — Searches types by interface or base class
Requirements
- .NET 8.0 or higher
dotnetCLI available in PATH (for build functionality)
Documentation
- Usage Guide — Patterns, examples, and best practices
- API Reference — Complete API documentation
License
MIT License — see LICENSE for details.
Part of the Forlet framework.
| 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 was computed. 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.
-
net8.0
- System.Reflection.MetadataLoadContext (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.