Oakton 3.0.0


"Opts" Files

Command Assembly Discovery Edit on GitHub

This feature probably won't be commonly used, but there is a mechanism to automatically find and load Oakton commands from other assemblies through file scanning.

The first step is to mark any assembly containing Oakton commands you want discovered and loaded through this mechanism with this attribute:


Next, when you build a CommandFactory, you need to explicitly opt into the auto-discovery of commands by using the RegisterCommandsFromExtensionAssemblies() option as shown below in the Oakton.AspNetCore code:

return CommandExecutor.For(factory =>
    if (applicationAssembly != null) factory.RegisterCommands(applicationAssembly);

    // This method will direct the CommandFactory to go look for extension
    // assemblies with Oakton commands

    factory.ConfigureRun = cmd =>
        if (cmd.Input is NetCoreInput) cmd.Input.As<NetCoreInput>().HostBuilder = source;