JasperFx / oakton

Parsing and Utilities for Command Line Tools in .Net
http://jasperfx.github.io/oakton
Apache License 2.0
308 stars 41 forks source link

Console application doesn't exit when using RunOaktonCommands for HostBuilder #59

Closed nzscout closed 2 years ago

nzscout commented 2 years ago

When using code below the application remains running after Startup.StartAsync completed. When I replace .RunOaktonCommands(args); with .RunConsoleAsync(); it shuts down fine

       static Task<int> Main(string[] args)
        {
            var configuration = new ConfigurationBuilder()
                .SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json")
                .AddJsonFile($"appsettings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") ?? "Production"}.json", true)
                .Build();

            return CreateHostBuilder(args).ConfigureLogging(logging =>
                {
                    logging.ClearProviders();
                }
                )
                .UseSerilog()
                .ConfigureServices((_, services) =>
                {
                    services.AddDescription<OaktonConfigDescription>();
                    services.AddHostedService<Startup>();
                }
                ).RunOaktonCommands(args); 
        }
jeremydmiller commented 2 years ago

Sorry, just now seeing this. Oakton shouldn't be exiting if you just run "run". By design, it should hold the host until you call CTRL-C in this case.