MinimalApiGen 1.0.0
dotnet add package MinimalApiGen --version 1.0.0
NuGet\Install-Package MinimalApiGen -Version 1.0.0
<PackageReference Include="MinimalApiGen" Version="1.0.0" />
<PackageVersion Include="MinimalApiGen" Version="1.0.0" />
<PackageReference Include="MinimalApiGen" />
paket add MinimalApiGen --version 1.0.0
#r "nuget: MinimalApiGen, 1.0.0"
#:package MinimalApiGen@1.0.0
#addin nuget:?package=MinimalApiGen&version=1.0.0
#tool nuget:?package=MinimalApiGen&version=1.0.0
MinimalApiGen
Compile-time Roslyn source generator that auto-registers ASP.NET Core Minimal API endpoints. Zero reflection · Native AOT safe · No runtime dependency.
Decorate a plain static class with [RouteGroup] and [Get]/[Post]/[Put]/[Patch]/[Delete],
and MinimalApiGen emits a single MapGeneratedEndpoints() extension method at build time —
replacing hand-written app.MapGet(...) boilerplate with one line in Program.cs. Route-parameter
mismatches and non-static handlers are caught as compiler errors, not runtime 404s.
Supported .NET versions
| Target framework | Supported |
|---|---|
| .NET 8.0 | ✅ |
| .NET 9.0 | ✅ |
| .NET 10.0 | ✅ |
The package targets netstandard2.0 for both the attributes and the generator, so it works
unmodified on any current or future .NET version that implements netstandard2.0 — .NET 8, 9,
and 10 are the versions actively built and tested in this repository's CI and sample app
(samples/MinimalApiGen.Sample multi-targets all three). The generator itself is a build-time-only
component (analyzers/dotnet/cs), so it never affects your app's target framework or its Native
AOT / trimming compatibility.
Installation
dotnet add package MinimalApiGen
This single package brings in everything you need:
- The
[RouteGroup]/[Get]/[Post]/… attribute types, added as a normal reference. - The source generator itself, wired in automatically as a Roslyn analyzer — no other setup,
no
<Analyzer>entries, nothing to add toProgram.csbesides the one line shown below.
How to use it — step by step
Install the package in your ASP.NET Core project (see above).
Create an endpoint class. Use a
staticclass, tag it with[RouteGroup("/prefix")], and tag each handler method with an HTTP-verb attribute. Handler methods must bestatic:// Endpoints/ProductEndpoints.cs using MinimalApiGen; [RouteGroup("/api/products")] public static class ProductEndpoints { [Get("")] [EndpointMeta("List all products")] public static IResult GetAll(ProductService svc) => Results.Ok(svc.GetAll()); [Get("{id:int}")] public static IResult GetById(int id, ProductService svc) => svc.GetById(id) is { } p ? Results.Ok(p) : Results.NotFound(); [Post("")] [AuthorizeEndpoint("Admin")] public static IResult Create(CreateProductRequest req, ProductService svc) { var product = svc.Create(req); return Results.Created($"/api/products/{product.Id}", product); } }Build the project. The generator runs automatically on every build — there's no extra step. If a route template references a parameter your method doesn't declare (e.g.
[Get("{id:int}")]on a method with noidparameter), the build fails immediately with aMAG001compiler error instead of surfacing as a runtime 404 later.Register everything with one line in
Program.cs:using MinimalApiGen.Generated; var builder = WebApplication.CreateBuilder(args); builder.Services.AddSingleton<ProductService>(); builder.Services.AddAuthorization(); var app = builder.Build(); app.UseAuthorization(); app.MapGeneratedEndpoints(); // ← every [RouteGroup]-decorated class, one line app.Run();Run your app as normal (
dotnet run). Every endpoint from every[RouteGroup]class in your project is registered — add a new endpoint method any time and it's picked up on the next build, with no change needed toProgram.cs.(Optional) Exclude an endpoint from generation with
[ExcludeFromGeneration]and map it yourself, for handlers too complex for attribute declaration:[ExcludeFromGeneration] public static IResult Search(string q, ProductService svc) => /* ... */; // Program.cs, after MapGeneratedEndpoints(): app.MapGet("/api/products/search", ProductEndpoints.Search);
See samples/MinimalApiGen.Sample in the source repository for a complete, runnable ASP.NET Core
project using every attribute below, including versioned endpoints and route groups for two
separate resources.
Attributes
| Attribute | Target | Purpose |
|---|---|---|
[RouteGroup("/prefix")] |
Class | Required. Sets the route prefix for all methods in the class. Emits .WithTags(...) on every endpoint using the optional Tag property, or the class name if Tag is unset. |
[Get/Post/Put/Patch/Delete("template")] |
Method (must be static) |
Maps the method to an HTTP verb + optional route template, relative to the group prefix. |
[AuthorizeEndpoint] / [AuthorizeEndpoint("PolicyName")] |
Method or Class | Emits .RequireAuthorization() or .RequireAuthorization("PolicyName"). A method-level attribute wins; otherwise a class-level one is inherited by every method in the class. |
[AllowAnonymousEndpoint] |
Method | Emits .AllowAnonymous(). Also the way to opt one method out of a class-level [AuthorizeEndpoint] — this is not flagged as a conflict (MAG004 only fires when a method has both attributes directly on itself). |
[ApiVersion("2.0")] |
Class or Method | Emits .WithGroupName("2.0"). A method-level attribute wins; otherwise a class-level one applies to every method. Note: this only adds an OpenAPI grouping label — it does not integrate with a versioning middleware such as Asp.Versioning. |
[EndpointMeta("Summary")] |
Method | Emits .WithSummary("Summary") for OpenAPI; optional Description property also emits .WithDescription(...). |
[ExcludeFromGeneration] |
Method | Skips this method entirely — register it manually after MapGeneratedEndpoints(). |
Diagnostics
| Code | Severity | Meaning |
|---|---|---|
| MAG001 | Error | Route template has a {param} with no matching method argument. |
| MAG002 | Error | HTTP verb method is not static. |
| MAG003 | Warning | Class has HTTP verb methods but is missing [RouteGroup]. |
| MAG004 | Warning | Method has both [AuthorizeEndpoint] and [AllowAnonymousEndpoint]. |
Versioning
This package follows Semantic Versioning 2.0:
- MAJOR — breaking attribute/API changes, or a change to the shape of generated code that
requires consumer changes (e.g. renaming
MapGeneratedEndpoints). - MINOR — new attributes, new diagnostics, or new optional behavior that doesn't break existing consumers.
- PATCH — generator/diagnostic bug fixes with no API surface change.
See the package's release notes on NuGet (or PackageReleaseNotes in
src/MinimalApiGen/MinimalApiGen.csproj) for the changelog of each published version.
| Version | Notes |
|---|---|
| 1.0.0 | Initial release. Full attribute set (including [RouteGroup].Tag → .WithTags(...), [EndpointMeta].Description → .WithDescription(...), and class-level [AuthorizeEndpoint] inheritance), MAG001–MAG004 diagnostics, .NET 8/9/10 support. |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
This package has no dependencies.
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 |
|---|---|---|
| 1.0.0 | 111 | 9/2/2026 |
1.0.0
- Initial release.
- Attributes: RouteGroup (route prefix + OpenAPI Tag), Get/Post/Put/Patch/Delete, AuthorizeEndpoint (method- or class-level, with method-level taking precedence and AllowAnonymousEndpoint able to opt a method out of a class-level policy), AllowAnonymousEndpoint, ApiVersion, EndpointMeta (Summary + Description), ExcludeFromGeneration.
- Diagnostics: MAG001 (missing route param), MAG002 (method must be static), MAG003 (missing [RouteGroup]), MAG004 (conflicting auth attributes on the same method).
- Supports .NET 8.0, 9.0 and 10.0 (and any netstandard2.0-compatible target) — zero reflection, Native AOT safe.