Oakton 2.0.0


Next

Run

Previous

Command Assembly Discovery

Extended ASP.Net Core Command Line Options Edit on GitHub


The Oakton.AspNetCore library can be used to extend the command line options of the typical ASP.Net Core application for:

To enable the extended command line options in your ASP.Net Core application, first install the Oakton.AspNetCore nuget to your project. Then modify the Program.Main() method generated by the baseline mvc or other ASP.Net Core services to this:


public class Program
{
    public static Task<int> Main(string[] args)
    {
        return CreateWebHostBuilder(args)
            
            // This extension method replaces the calls to
            // IWebHost.Build() and Start()
            .RunOaktonCommands(args);
    }

    public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
        WebHost.CreateDefaultBuilder(args)
            .UseStartup<Startup>();
    
}

There are just a couple things to note:

  1. The return value of the Program.Main() method now needs to be Task<int> rather than void. This is done so that Oakton can return either successful or failure exit codes for usage in diagnostic commands you may want to stop automated builds upon failures.
  2. You will use the RunOaktonCommands() method to accept the command line arguments and invoke your system rather than manually building and/or starting the IWebHost yourself