Skip to content
DocsTry Aspire
DocsTry

TerminalResourceBuilderExtensions Methods

ClassMethods1 member
Provides extension methods for configuring interactive terminal support on resources.
WithTerminal(IResourceBuilder<T>, Action<TerminalOptions>)Section titled WithTerminal(IResourceBuilder<T>, Action<TerminalOptions>)extensionIResourceBuilder<T>
Configures a resource to expose an interactive terminal session.
public static class TerminalResourceBuilderExtensions
{
public static IResourceBuilder<T> WithTerminal<T>(
this IResourceBuilder<T> builder,
Action<TerminalOptions>? configure = null)
{
// ...
}
}
builderIResourceBuilder<T>The resource builder.
configureAction<TerminalOptions>optionalAn optional callback to configure the terminal options.
IResourceBuilder<T>A reference to the ApplicationModel.IResourceBuilder`1 for chaining additional configuration.

When a resource is configured with .WithTerminal(), DCP allocates a pseudo-terminal (PTY) per replica and a hidden terminal host process bridges the PTY traffic over Hex1b's HMP v1 protocol. The terminal session can be accessed from the Aspire Dashboard's terminal page or via the aspire terminal CLI command.

One terminal host process is spawned per parent replica (e.g. WithReplicas(3).WithTerminal() → 3 terminal host processes named {parent}-terminalhost-0 .. {parent}-terminalhost-2). The order of WithReplicas(...) and WithTerminal() does not matter: the per-replica hosts are materialized during BeforeStartEvent after the model is fully built, so the final replica count is always honoured.

Add terminal support to an executable resource:

var agent = builder.AddExecutable("agent", "my-agent", ".")
.WithTerminal();

Add terminal support with custom dimensions to a multi-replica resource. The order of WithReplicas and WithTerminal does not matter:

var agent = builder.AddExecutable("agent", "my-agent", ".")
.WithReplicas(3)
.WithTerminal(options =>
{
options.Columns = 200;
options.Rows = 50;
});