KestrelCgi 0.0.2

dotnet add package KestrelCgi --version 0.0.2
                    
NuGet\Install-Package KestrelCgi -Version 0.0.2
                    
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="KestrelCgi" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="KestrelCgi" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="KestrelCgi" />
                    
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 KestrelCgi --version 0.0.2
                    
#r "nuget: KestrelCgi, 0.0.2"
                    
#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 KestrelCgi@0.0.2
                    
#: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=KestrelCgi&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=KestrelCgi&version=0.0.2
                    
Install as a Cake Tool

KestrelCgi

KestrelCgi implements a simple CGI server directly on top of Kestrel.

How it works

An example is provided in Demo/Program.cs:

First, implement ICgiHttpContent:

class ExampleCgiContext : ICgiHttpContext
{
    public required HttpContext HttpContext { get; set; }

    public bool LogErrorOutput { get; set; } = true;

    public TimeSpan ProcessingTimeout { get; set; } = TimeSpan.FromSeconds(3);
}

Then, derive from the abstract class CgiHttpApplication and implement GetCgiExecutionInfo to provide CgiExecutionInfo which gives necessary information on how to execute a CGI program:

class ExampleCgiServer(ILogger? logger = null) : CgiHttpApplication<ExampleCgiContext>(logger)
{
    public override ExampleCgiContext CreateContext(IFeatureCollection contextFeatures)
    {
        ExampleCgiContext context = new() { HttpContext = new DefaultHttpContext(contextFeatures) };

        return context;
    }

    public override CgiExecutionInfo? GetCgiExecutionInfo(ExampleCgiContext context)
    {
        var request = context.HttpContext.Request;

        if (request.Path.StartsWithSegments(@"/env.fsx"))
        {
            const string scriptName = "/env.fsx";
            var pathInfo = request.Path.Value![scriptName.Length..];
            var envUpdate = new Dictionary<string, string> { { "FOO", "BAR" } };

            CgiExecutionInfo result = new(
                ScriptName: "env.fsx",
                PathInfo: pathInfo,
                CommandPath: "dotnet",
                CommandArgs: ["fsi", Path.Join(".", "script", "env.fsx")],
                EnvironmentUpdate: envUpdate
            );

            return result;
        }
        else
        {
            return null;
        }
    }
}

Now it can be run on a KestrelServer:

KestrelServer server = new(/*...*/);
server.StartAsync(new ExampleCgiServer(), CancellationToken.None);

See it in action

In the root directory, run:

cd Demo
dotnet run

Then in a Web browser, navigate to http://localhost:5001/env.fsx to see the output of the F# script.

Futhermore, the repository is served by git http-backend at http://127.0.0.1:5001/git which can be cloned like:

git clone http://127.0.0.1:5001/git/ new_repo

Installation

Install the nuget package:

dotnet package add KestrelCgi

For local instanll, a --source switch can be specified to indicate the directory where the nuget package resides.

Project Setup

Your .csproj needs reference to framework Microsoft.AspNetCore.App for Kestrel related stuff (see Demo/Demo.csproj):

  <ItemGroup>
    <FrameworkReference Include="Microsoft.AspNetCore.App" />
  </ItemGroup>

How to package the nuget

In the root directory, run:

dotnet pack Lib -o nupkg
Product 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

    • 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
0.0.2 91 2/18/2026
0.0.1 177 11/8/2025