ApiFeatures.Systems.Apis
9.0.2
dotnet add package ApiFeatures.Systems.Apis --version 9.0.2
NuGet\Install-Package ApiFeatures.Systems.Apis -Version 9.0.2
<PackageReference Include="ApiFeatures.Systems.Apis" Version="9.0.2" />
<PackageVersion Include="ApiFeatures.Systems.Apis" Version="9.0.2" />
<PackageReference Include="ApiFeatures.Systems.Apis" />
paket add ApiFeatures.Systems.Apis --version 9.0.2
#r "nuget: ApiFeatures.Systems.Apis, 9.0.2"
#:package ApiFeatures.Systems.Apis@9.0.2
#addin nuget:?package=ApiFeatures.Systems.Apis&version=9.0.2
#tool nuget:?package=ApiFeatures.Systems.Apis&version=9.0.2
ApiFeatures.Systems.Apis
System information API module for ASP.NET Core applications.
Features
- System version endpoint returning commit hash and branch name
- Minimal API implementation
- OpenAPI/Swagger support
- Optional authorization policy support
Installation
dotnet add package ApiFeatures.Systems.Apis
Usage
Register the feature
// In Program.cs
var addSystemFeatureOptions = new AddSystemFeatureOptions();
addSystemFeatureOptions.WithSystemVersionRetrievalFactory(serviceProvider =>
{
// Return system version information
// You can retrieve this from configuration, git info, etc.
return new SystemVersionDto(
commitHash: "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0",
branchName: "main"
);
});
builder.Services.AddSystemFeature(addSystemFeatureOptions);
Add endpoints
// Map endpoints
app.AddSystemEndpoints();
// Or with authorization policy
var policy = new AuthorizationPolicyBuilder()
.RequireAuthenticatedUser()
.Build();
app.AddSystemEndpoints(new AddSystemEndpointsOptions()
.WithAuthorizationPolicy(() => policy));
Print System Version During Startup
You can retrieve and log the system version information during application startup. The SystemVersionDto is registered as a singleton in the dependency injection container and can be accessed after building the application.
// After building the app
var app = builder.Build();
// Get logger
var logger = app.Logger;
// Retrieve and print system version information
var systemVersionDto = app.Services.GetRequiredService<SystemVersionDto>();
logger.LogInformation("System Version Information:");
logger.LogInformation("Commit Hash: {CommitHash}", systemVersionDto.CommitHash);
logger.LogInformation("Branch Name: {BranchName}", systemVersionDto.BranchName);
// Continue with middleware configuration
app.Run();
Console Output Example:
[14:32:15 INF] System Version Information:
[14:32:15 INF] Commit Hash: a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0
[14:32:15 INF] Branch Name: features/system-version-endpoints
Use Cases:
- Display build information at application startup for troubleshooting
- Log deployment version in production environments
- Track which code version is running in each environment
- Include in startup banner or health check endpoints
- Audit trail for deployed versions
Best Practices:
- Log this information early in the startup process for visibility
- Use structured logging (as shown) for easy parsing in log aggregation tools
- Consider logging to both console and file sinks
- Include in application startup logs for production deployments
Complete Example
Here's a complete example showing the full integration:
using ApiFeatures.Systems.Apis.Extensions;
using ApiFeatures.Systems.Apis.Models;
using ApiFeatures.Systems.Apis.Models.Dtos;
var builder = WebApplication.CreateBuilder(args);
// Add System feature with version information
var addSystemFeatureOptions = new AddSystemFeatureOptions();
addSystemFeatureOptions.WithSystemVersionRetrievalFactory(_ =>
{
return new SystemVersionDto(
commitHash: "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0",
branchName: "features/system-version-endpoints"
);
});
builder.Services.AddSystemFeature(addSystemFeatureOptions);
var app = builder.Build();
var logger = app.Logger;
// Add System endpoints
app.AddSystemEndpoints();
// Print system version at startup
var systemVersionDto = app.Services.GetRequiredService<SystemVersionDto>();
logger.LogInformation("System Version Information:");
logger.LogInformation("Commit Hash: {CommitHash}", systemVersionDto.CommitHash);
logger.LogInformation("Branch Name: {BranchName}", systemVersionDto.BranchName);
app.Run();
Advanced: Retrieving Git Information Dynamically
For production deployments, you might want to retrieve git information during build time:
// Using environment variables set during CI/CD
addSystemFeatureOptions.WithSystemVersionRetrievalFactory(_ =>
{
var commitHash = Environment.GetEnvironmentVariable("GIT_COMMIT") ?? "unknown";
var branchName = Environment.GetEnvironmentVariable("GIT_BRANCH") ?? "unknown";
return new SystemVersionDto(
commitHash: commitHash,
branchName: branchName
);
});
// Using configuration
addSystemFeatureOptions.WithSystemVersionRetrievalFactory(serviceProvider =>
{
var configuration = serviceProvider.GetRequiredService<IConfiguration>();
var commitHash = configuration["SystemVersion:CommitHash"] ?? "unknown";
var branchName = configuration["SystemVersion:BranchName"] ?? "unknown";
return new SystemVersionDto(
commitHash: commitHash,
branchName: branchName
);
});
API Endpoints
Get System Version
GET /api/system/version
Response:
{
"commitHash": "a1b2c3d4e5f6g7h8i9j0k1l2m3n4o5p6q7r8s9t0",
"branchName": "features/system-version-endpoints"
}
License
Proprietary
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net9.0 is compatible. 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. |
-
net9.0
- Microsoft.AspNetCore.OpenApi (>= 9.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.
| Version | Downloads | Last Updated |
|---|---|---|
| 9.0.2 | 33 | 5/7/2026 |