Skip to content

NET_Core_Hosting

Denis Zykov edited this page Jan 10, 2024 · 2 revisions

You can run your command line application within the .NET Generic Host. For this you need a Nuget package:

Install-Package deniszykov.CommandLine.Hosted

And the following application startup code:

internal class Program
{
    private static async Task Main(string[] args)
    {
        await CreateHostBuilder(args).Build().RunAsync();
    }

    private static IHostBuilder CreateHostBuilder(string[] args) =>
        Host.CreateDefaultBuilder(args)

        .ConfigureServices((context, services) => {
            // un-comment if you want to configure CommandLine from appsettings.json file
            // services.Configure<CommandLineConfiguration>(context.Configuration.GetSection("CommandLine"));
        })

        .ConfigureCommandLineHost(args, builder => {
            builder.Use<Program>();
        });
}
Clone this wiki locally