Table of Contents

Class HostBuilderExtensions

Namespace
Microsoft.Extensions.Hosting
Assembly
McMaster.Extensions.Hosting.CommandLine.dll

Extension methods for IHostBuilder support.

public static class HostBuilderExtensions
Inheritance
object
HostBuilderExtensions

Methods

RunCommandLineApplicationAsync(IHostBuilder, string[], Action<CommandLineApplication>, CancellationToken)

Runs an instance of CommandLineApplication using builder API to provide command line parsing on the given args.

public static Task<int> RunCommandLineApplicationAsync(this IHostBuilder hostBuilder, string[] args, Action<CommandLineApplication> configure, CancellationToken cancellationToken = default)

Parameters

hostBuilder IHostBuilder

This instance

args string[]

The command line arguments

configure Action<CommandLineApplication>

The delegate to configure the application

cancellationToken CancellationToken

A cancellation token

Returns

Task<int>

A task whose result is the exit code of the application

RunCommandLineApplicationAsync<TApp>(IHostBuilder, string[], Action<CommandLineApplication<TApp>>, CancellationToken)

Runs an instance of TApp using CommandLineApplication to provide command line parsing on the given args. This method should be the primary approach taken for command line applications.

public static Task<int> RunCommandLineApplicationAsync<TApp>(this IHostBuilder hostBuilder, string[] args, Action<CommandLineApplication<TApp>> configure, CancellationToken cancellationToken = default) where TApp : class

Parameters

hostBuilder IHostBuilder

This instance

args string[]

The command line arguments

configure Action<CommandLineApplication<TApp>>

The delegate to configure the application

cancellationToken CancellationToken

A cancellation token

Returns

Task<int>

A task whose result is the exit code of the application

Type Parameters

TApp

The type of the command line application implementation

RunCommandLineApplicationAsync<TApp>(IHostBuilder, string[], CancellationToken)

Runs an instance of TApp using CommandLineApplication to provide command line parsing on the given args. This method should be the primary approach taken for command line applications.

public static Task<int> RunCommandLineApplicationAsync<TApp>(this IHostBuilder hostBuilder, string[] args, CancellationToken cancellationToken = default) where TApp : class

Parameters

hostBuilder IHostBuilder

This instance

args string[]

The command line arguments

cancellationToken CancellationToken

A cancellation token

Returns

Task<int>

A task whose result is the exit code of the application

Type Parameters

TApp

The type of the command line application implementation

UseCommandLineApplication<TApp>(IHostBuilder, string[])

Configures an instance of TApp using CommandLineApplication to provide command line parsing on the given args.

public static IHostBuilder UseCommandLineApplication<TApp>(this IHostBuilder hostBuilder, string[] args) where TApp : class

Parameters

hostBuilder IHostBuilder

This instance

args string[]

The command line arguments

Returns

IHostBuilder

IHostBuilder

Type Parameters

TApp

The type of the command line application implementation

UseCommandLineApplication<TApp>(IHostBuilder, string[], Action<CommandLineApplication<TApp>>)

Configures an instance of TApp using CommandLineApplication to provide command line parsing on the given args.

public static IHostBuilder UseCommandLineApplication<TApp>(this IHostBuilder hostBuilder, string[] args, Action<CommandLineApplication<TApp>> configure) where TApp : class

Parameters

hostBuilder IHostBuilder

This instance

args string[]

The command line arguments

configure Action<CommandLineApplication<TApp>>

The delegate to configure the application

Returns

IHostBuilder

IHostBuilder

Type Parameters

TApp

The type of the command line application implementation

See Also