Watch Aspire live streams文档试用 Aspire
Watch Aspire live streams文档试用

Certificate configuration

此内容尚不支持你的语言。

Aspire provides two complementary sets of certificate APIs:

  1. HTTPS endpoint APIs: Configure the certificates that resources use for their own HTTPS endpoints (server authentication)
  2. Certificate trust APIs: Configure which certificates resources trust when making outbound HTTPS connections (client authentication)

Both sets of APIs work together to enable secure HTTPS communication during local development. For example, a Vite frontend might use WithHttpsDeveloperCertificate to serve HTTPS traffic, while also using WithDeveloperCertificateTrust to trust the dashboard’s OTLP endpoint certificate.

HTTPS is essential for protecting the security and privacy of data transmitted between services. It encrypts traffic to prevent eavesdropping, tampering, and man-in-the-middle attacks. For production environments, HTTPS is a fundamental security requirement.

However, enabling HTTPS during local development to match the production configuration presents unique challenges. Development environments typically use self-signed certificates that browsers and applications don’t trust by default. Managing these certificates across multiple services, containers, and different language runtimes can be complex and time-consuming, often creating friction in the development workflow.

Aspire simplifies HTTPS configuration for local development by providing APIs to:

  • Configure HTTPS endpoints with appropriate certificates for server authentication
  • Manage certificate trust so resources can communicate with services using self-signed certificates
  • Automatically handle the development certificate (a per-user self-signed certificate valid only for local domains) across different resource types

Many of the certificate features in Aspire rely on a development certificate. Before using these features, you need to ensure that a trusted development certificate is installed on your machine.

The preferred way to manage the development certificate is to use the Aspire CLI. When you run aspire run in an interactive session, the CLI automatically ensures the development certificate is created and trusted. No additional manual steps are required.

For non-C# AppHosts (such as TypeScript or Python AppHosts), the dotnet first-run experience that normally creates the HTTPS development certificate never runs, because these AppHosts launch a prebuilt native binary instead of invoking dotnet. The Aspire CLI fills this gap when aspire run starts and no development certificate exists:

  • In an interactive session—and on Linux, where establishing trust doesn’t require a prompt—the CLI creates and trusts the certificate, just as it does for C# AppHosts.
  • In a non-interactive session on macOS or Windows (for example, in CI), the CLI can’t show the macOS Keychain password prompt or the Windows trust dialog, so it generates the certificate without trusting it. This lets servers such as Kestrel load the certificate from the personal store, even though it isn’t trusted. If the certificate can’t be generated, a warning is displayed and the run continues.

To opt out of automatic certificate generation, set the ASPIRE_CLI_GENERATE_HTTPS_CERTIFICATE environment variable to false. This mirrors the .NET SDK’s DOTNET_GENERATE_ASPNET_CERTIFICATE opt-out:

Disable automatic HTTPS certificate generation
ASPIRE_CLI_GENERATE_HTTPS_CERTIFICATE=false aspire run

You can also manage certificates explicitly with the Aspire CLI:

Trust the development certificate
aspire certs trust
Remove and re-trust (refresh)
aspire certs clean
aspire certs trust

Developer certificate for DCP communication

Section titled “Developer certificate for DCP communication”

By default, Aspire uses the ASP.NET Core developer certificate to secure communication with its internal Developer Control Plane (DCP) server. This replaces the ephemeral localhost certificate that DCP would otherwise generate itself, and avoids certificate trust errors caused by that certificate not being in the system trust store.

If no trusted developer certificate is found, Aspire automatically falls back to DCP’s ephemeral certificate.

To opt out and use DCP’s default ephemeral certificate instead, set ASPIRE_DCP_USE_DEVELOPER_CERTIFICATE to false in your AppHost’s launchSettings.json or as an environment variable:

Properties/launchSettings.json
{
"profiles": {
"https": {
"commandName": "Project",
"environmentVariables": {
"ASPIRE_DCP_USE_DEVELOPER_CERTIFICATE": "false"
}
}
}
}

HTTPS endpoint configuration determines which certificate a resource presents when serving HTTPS traffic. This is server-side certificate configuration for resources that host HTTPS/TLS endpoints.

For resources that have a certificate configuration defined with WithHttpsCertificateConfiguration, Aspire attempts to configure it to use the development certificate if available. This automatic configuration works for many common resource types including YARP, Redis, and Keycloak containers; Vite based JavaScript apps; and Python apps using Uvicorn.

You can control this behavior using the HTTPS endpoint APIs described below.

To explicitly configure a resource to use the development certificate for its HTTPS endpoints:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
// Explicitly use the developer certificate
const
const nodeApp: ViteAppResource
nodeApp
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addViteApp(name: string, appDirectory: string, options?: {
runScriptName?: string;
}): ViteAppResource (+1 overload)

Adds a Vite app to the distributed application builder.

addViteApp
("frontend", "../frontend")
.
ExecutableResource.withHttpsDeveloperCertificate(options?: {
password?: string | ParameterResource;
} | undefined): ViteAppResource (+1 overload)

Indicates that a resource should use the developer certificate key pair for HTTPS endpoints at run time. Currently this indicates use of the ASP.NET Core developer certificate. The developer certificate will only be used when running in local development scenarios; in publish mode resources will use their default certificate configuration.

withHttpsDeveloperCertificate
();
// Use developer certificate with an encrypted private key
const
const certPassword: ParameterResource
certPassword
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addParameter(name: string, options?: {
value?: string;
publishValueAsDefault?: boolean;
secret?: boolean;
}): ParameterResource (+1 overload)

Adds a parameter resource

addParameter
("cert-password", {
secret?: boolean | undefined
secret
: true });
const
const pythonApp: UvicornAppResource
pythonApp
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addUvicornApp(name: string, appDirectory: string, app: string): UvicornAppResource

Adds a Uvicorn-based Python application to the distributed application builder with HTTP endpoint configuration.

addUvicornApp
("api", "../api", "app:main")
.
ExecutableResource.withHttpsDeveloperCertificate(options?: {
password?: string | ParameterResource;
} | undefined): UvicornAppResource (+1 overload)

Indicates that a resource should use the developer certificate key pair for HTTPS endpoints at run time. Currently this indicates use of the ASP.NET Core developer certificate. The developer certificate will only be used when running in local development scenarios; in publish mode resources will use their default certificate configuration.

withHttpsDeveloperCertificate
({
password?: string | ParameterResource | undefined
password
:
const certPassword: ParameterResource
certPassword
});
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

The WithHttpsDeveloperCertificate method:

  • Configures the resource to use the development certificate
  • Only applies in run mode (local development)
  • Optionally accepts a password parameter for encrypted certificate private keys
  • Works with containers, Node.js, Python, and other resource types

To configure a resource to use a specific X.509 certificate for HTTPS endpoints:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
,
function refExpr(strings: TemplateStringsArray, ...values: unknown[]): ReferenceExpression

Creates a reference expression from a tagged template literal

refExpr
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
const
const api: ContainerResource
api
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addContainer(name: string, image: AddContainerOptions): ContainerResource

Adds a container resource to the application.

addContainer
("api", {
AddContainerOptions.image?: string | undefined
image
: "my-api",
AddContainerOptions.tag?: string | undefined
tag
: "latest",
});
const api: ContainerResource
api
.
ContainerResource.createExecutionConfiguration(): IExecutionConfigurationBuilder

Creates an execution configuration builder for the specified resource.

createExecutionConfiguration
()
.
IExecutionConfigurationBuilder.withArgumentsConfig(): IExecutionConfigurationBuilder

Adds a command line arguments configuration gatherer to the builder.

withArgumentsConfig
()
.
IExecutionConfigurationBuilder.withEnvironmentVariablesConfig(): IExecutionConfigurationBuilder

Adds an environment variables configuration gatherer to the builder.

withEnvironmentVariablesConfig
()
.
IExecutionConfigurationBuilder.withHttpsCertificateConfig(configContextFactory: (arg: HttpsCertificateInfo) => Promise<HttpsCertificateExecutionConfigurationContext>): IExecutionConfigurationBuilder

Adds an HTTPS certificate configuration gatherer using certificate metadata instead of a raw X509 certificate.

withHttpsCertificateConfig
(async () => ({
HttpsCertificateExecutionConfigurationContext.certificatePath?: ReferenceExpression | undefined
certificatePath
:
function refExpr(strings: TemplateStringsArray, ...values: unknown[]): ReferenceExpression

Creates a reference expression from a tagged template literal

refExpr
`/certs/tls.crt`,
HttpsCertificateExecutionConfigurationContext.keyPath?: ReferenceExpression | undefined
keyPath
:
function refExpr(strings: TemplateStringsArray, ...values: unknown[]): ReferenceExpression

Creates a reference expression from a tagged template literal

refExpr
`/certs/tls.key`,
HttpsCertificateExecutionConfigurationContext.pfxPath?: ReferenceExpression | undefined
pfxPath
:
function refExpr(strings: TemplateStringsArray, ...values: unknown[]): ReferenceExpression

Creates a reference expression from a tagged template literal

refExpr
`/certs/tls.pfx`,
}));
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

The certificate must:

  • Include a private key
  • Be a valid X.509 certificate
  • Be appropriate for server authentication

To prevent Aspire from configuring any HTTPS certificate for a resource:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
// Disable automatic HTTPS certificate configuration
const
const redis: IResourceWithEnvironment
redis
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addRedis(name: string, options?: {
port?: number;
password?: string | ParameterResource;
}): RedisResource (+1 overload)

Adds a Redis container to the application model.

addRedis
("cache")
.
ContainerResource.withoutHttpsCertificate(): IResourceWithEnvironment

Disable HTTPS/TLS server certificate configuration for the resource. No HTTPS/TLS termination configuration will be applied.

withoutHttpsCertificate
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

Use WithoutHttpsCertificate when:

  • The resource doesn’t support HTTPS
  • You want to manually configure certificates
  • The resource has its own certificate management

For resources that need custom certificate configuration logic, use WithHttpsCertificateConfiguration to specify how certificate files should be passed to the resource:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
,
function refExpr(strings: TemplateStringsArray, ...values: unknown[]): ReferenceExpression

Creates a reference expression from a tagged template literal

refExpr
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
const
const api: ContainerResource
api
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addContainer(name: string, image: AddContainerOptions): ContainerResource

Adds a container resource to the application.

addContainer
("api", {
AddContainerOptions.image?: string | undefined
image
: "myimage",
AddContainerOptions.tag?: string | undefined
tag
: "latest",
});
const api: ContainerResource
api
.
ContainerResource.createExecutionConfiguration(): IExecutionConfigurationBuilder

Creates an execution configuration builder for the specified resource.

createExecutionConfiguration
()
.
IExecutionConfigurationBuilder.withArgumentsConfig(): IExecutionConfigurationBuilder

Adds a command line arguments configuration gatherer to the builder.

withArgumentsConfig
()
.
IExecutionConfigurationBuilder.withEnvironmentVariablesConfig(): IExecutionConfigurationBuilder

Adds an environment variables configuration gatherer to the builder.

withEnvironmentVariablesConfig
()
.
IExecutionConfigurationBuilder.withCertificateTrustConfig(configContextFactory: (arg: CertificateTrustScope) => Promise<CertificateTrustExecutionConfigurationContext>): IExecutionConfigurationBuilder

Adds a certificate trust configuration gatherer to the builder.

withCertificateTrustConfig
(async () => ({
CertificateTrustExecutionConfigurationContext.certificateBundlePath?: ReferenceExpression | undefined
certificateBundlePath
:
function refExpr(strings: TemplateStringsArray, ...values: unknown[]): ReferenceExpression

Creates a reference expression from a tagged template literal

refExpr
`/certs/ca-bundle.crt`,
CertificateTrustExecutionConfigurationContext.certificateDirectoriesPath?: ReferenceExpression | undefined
certificateDirectoriesPath
:
function refExpr(strings: TemplateStringsArray, ...values: unknown[]): ReferenceExpression

Creates a reference expression from a tagged template literal

refExpr
`/certs`,
CertificateTrustExecutionConfigurationContext.rootCertificatesPath?: string | undefined
rootCertificatesPath
: "/etc/ssl/certs",
CertificateTrustExecutionConfigurationContext.isContainer?: boolean | undefined
isContainer
: true,
}));
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

The callback receives an HttpsCertificateConfigurationCallbackAnnotationContext that provides:

  • CertificatePath: Path to the certificate file in PEM format
  • KeyPath: Path to the private key file in PEM format
  • PfxPath: Path to the certificate in PFX/PKCS#12 format
  • Password: The password for the private key, if configured
  • Arguments: Command line arguments list to modify
  • EnvironmentVariables: Environment variables dictionary to modify
  • ExecutionContext: The current execution context
  • Resource: The resource being configured

Certificate trust configuration determines which certificates a resource trusts when making outbound HTTPS connections. This is client-side certificate configuration.

Certificate trust customization is valuable when:

  • Resources need to trust the development certificate for local HTTPS communication
  • Containerized services must communicate with the dashboard over HTTPS
  • Python or Node.js applications need to trust custom certificate authorities
  • You’re working with services that have specific certificate trust requirements
  • Resources need to establish secure telemetry connections to the Aspire dashboard

By default, Aspire attempts to add trust for the development certificate to resources that wouldn’t otherwise trust it. This enables resources to communicate with the dashboard OTLP collector endpoint over HTTPS and any other HTTPS endpoints secured by the development certificate.

You can control this behavior per resource using the WithDeveloperCertificateTrust API or through AppHost configuration settings.

Configure development certificate trust per resource

Section titled “Configure development certificate trust per resource”

To explicitly enable or disable development certificate trust for a specific resource:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
// Explicitly enable development certificate trust
const
const nodeApp: NodeAppResource
nodeApp
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource

Adds a node application to the application model. Node should be available on the PATH.

addNodeApp
("frontend", "../frontend", "index.js")
.
ExecutableResource.withDeveloperCertificateTrust(trust: boolean): NodeAppResource

Indicates whether developer certificates should be treated as trusted certificate authorities for the resource at run time. Currently this indicates trust for the ASP.NET Core developer certificate. The developer certificate will only be trusted when running in local development scenarios; in publish mode resources will use their default certificate trust.

withDeveloperCertificateTrust
(true);
// Disable development certificate trust
const
const pythonApp: PythonAppResource
pythonApp
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addPythonApp(name: string, appDirectory: string, scriptPath: string): PythonAppResource

Adds a Python application to the application model.

addPythonApp
("api", "../api", "main.py")
.
ExecutableResource.withDeveloperCertificateTrust(trust: boolean): PythonAppResource

Indicates whether developer certificates should be treated as trusted certificate authorities for the resource at run time. Currently this indicates trust for the ASP.NET Core developer certificate. The developer certificate will only be trusted when running in local development scenarios; in publish mode resources will use their default certificate trust.

withDeveloperCertificateTrust
(false);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

Certificate authority collections allow you to bundle custom certificates and make them available to resources. You create a collection using the AddCertificateAuthorityCollection method and then reference it from resources that need to trust those certificates.

Create and use a certificate authority collection

Section titled “Create and use a certificate authority collection”
AppHost.cs
using System.Security.Cryptography.X509Certificates;
var builder = DistributedApplication.CreateBuilder(args);
// Load your custom certificates
var certificates = new X509Certificate2Collection();
certificates.ImportFromPemFile("path/to/certificate.pem");
// Create a certificate authority collection
var certBundle = builder.AddCertificateAuthorityCollection("my-bundle")
.WithCertificates(certificates);
// Apply the certificate bundle to resources
builder.AddNpmApp("my-project", "../myapp")
.WithCertificateAuthorityCollection(certBundle);
builder.Build().Run();

In the preceding example, the certificate bundle is created with custom certificates and then applied to a Node.js application, enabling it to trust those certificates.

Certificate trust scopes control how custom certificates interact with a resource’s default trusted certificates. Different scopes provide flexibility in managing certificate trust based on your application’s requirements.

The WithCertificateTrustScope API accepts a CertificateTrustScope value to specify the trust behavior.

Aspire supports the following certificate trust scopes:

  • Append: Appends custom certificates to the default trusted certificates
  • Override: Replaces the default trusted certificates with only the configured certificates
  • System: Combines custom certificates with system root certificates and uses them to override the defaults
  • None: Disables all custom certificate trust configuration

Attempts to append the configured certificates to the default trusted certificates for a given resource. This mode is useful when you want to add trust for additional certificates while maintaining trust for the system’s default certificates.

This is the default scope for most resources. For Python resources, only OTEL trust configuration will be applied in this mode.

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
,
type CertificateTrustScope = "None" | "Append" | "Override" | "System"
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource

Adds a node application to the application model. Node should be available on the PATH.

addNodeApp
("api", "../api", "index.js")
.
ExecutableResource.withCertificateTrustScope(scope: CertificateTrustScope): NodeAppResource

Sets the certificate trust scope

withCertificateTrustScope
(
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
.
type Append: "Append"
Append
);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

Attempts to override a resource to only trust the configured certificates, replacing the default trusted certificates entirely. This mode is useful when you need strict control over which certificates are trusted.

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
var certBundle = builder.AddCertificateAuthorityCollection("custom-certs")
.WithCertificates(myCertificates);
builder.AddPythonModule("api", "./api", "uvicorn")
.WithCertificateAuthorityCollection(certBundle)
.WithCertificateTrustScope(CertificateTrustScope.Override);
builder.Build().Run();

Attempts to combine the configured certificates with the default system root certificates and use them to override the default trusted certificates for a resource. This mode is intended to support Python and similar runtimes that don’t work well with Append mode.

This is the default scope for Python projects because Python only has mechanisms to fully override certificate trust.

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
,
type CertificateTrustScope = "None" | "Append" | "Override" | "System"
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addPythonApp(name: string, appDirectory: string, scriptPath: string): PythonAppResource

Adds a Python application to the application model.

addPythonApp
("worker", "../worker", "main.py")
.
ExecutableResource.withCertificateTrustScope(scope: CertificateTrustScope): PythonAppResource

Sets the certificate trust scope

withCertificateTrustScope
(
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
.
type System: "System"
System
);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

Disables all custom certificate trust for the resource, causing it to rely solely on its default certificate trust behavior.

This is the default scope for .NET projects on Windows, as there’s no way to automatically change the default system store source.

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
,
type CertificateTrustScope = "None" | "Append" | "Override" | "System"
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addContainer(name: string, image: AddContainerOptions): ContainerResource

Adds a container resource to the application.

addContainer
("service", {
AddContainerOptions.image?: string | undefined
image
: "myimage",
AddContainerOptions.tag?: string | undefined
tag
: "latest" })
.
ContainerResource.withCertificateTrustScope(scope: CertificateTrustScope): ContainerResource

Sets the certificate trust scope

withCertificateTrustScope
(
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
.
type None: "None"
None
);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

For advanced scenarios, you can specify custom certificate trust behavior using a callback API. This callback allows you to customize the command line arguments and environment variables required to configure certificate trust for different resource types.

Configure certificate trust with a callback

Section titled “Configure certificate trust with a callback”

Use WithCertificateTrustConfiguration to customize how certificate trust is configured for a resource:

The callback receives a CertificateTrustConfigurationCallbackAnnotationContext that provides:

  • Scope: The CertificateTrustScope for the resource.
  • Arguments: Command line arguments for the resource. Values can be strings or path providers like CertificateBundlePath or CertificateDirectoriesPath.
  • EnvironmentVariables: Environment variables for configuring certificate trust. The dictionary key is the environment variable name; values can be strings or path providers. By default, includes SSL_CERT_DIR and may include SSL_CERT_FILE if Override or System scope is configured.
  • CertificateBundlePath: A value provider that resolves to the path of a custom certificate bundle file.
  • CertificateDirectoriesPath: A value provider that resolves to paths containing individual certificates.

Default implementations are provided for Node.js, Python, and container resources. Container resources rely on standard OpenSSL configuration options, with default values that support the majority of common Linux distributions.

For container resources, you can customize where certificates are stored and accessed using WithContainerCertificatePaths:

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddContainer("api", "myimage")
.WithContainerCertificatePaths(
customCertificatesDestination: "/custom/certs/path",
defaultCertificateBundlePaths: ["/etc/ssl/certs/ca-certificates.crt"],
defaultCertificateDirectoryPaths: ["/etc/ssl/certs"]);
builder.Build().Run();

The WithContainerCertificatePaths API accepts three optional parameters:

  • customCertificatesDestination: Overrides the base path in the container where custom certificate files are placed. If not set or set to null, the default path of /usr/lib/ssl/aspire is used.
  • defaultCertificateBundlePaths: Overrides the path(s) in the container where a default certificate authority bundle file is located. When the CertificateTrustScope is Override or System, the custom certificate bundle is additionally written to these paths. If not set or set to null, a set of default certificate paths for common Linux distributions is used.
  • defaultCertificateDirectoryPaths: Overrides the path(s) in the container where individual trusted certificate files are found. When the CertificateTrustScope is Append, these paths are concatenated with the path to the uploaded certificate artifacts. If not set or set to null, a set of default certificate paths for common Linux distributions is used.

This section demonstrates common patterns for configuring HTTPS endpoints and certificate trust together.

Configure a service with HTTPS and enable dashboard telemetry

Section titled “Configure a service with HTTPS and enable dashboard telemetry”

A typical scenario is configuring a Node.js service to serve HTTPS traffic while also enabling it to send telemetry to the dashboard:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
// Configure the service to use developer certificate for HTTPS endpoints
// and trust the developer certificate for outbound connections (like dashboard telemetry)
const
const frontend: NodeAppResource
frontend
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addNodeApp(name: string, appDirectory: string, scriptPath: string): NodeAppResource

Adds a node application to the application model. Node should be available on the PATH.

addNodeApp
("frontend", "../frontend", "index.js")
.
ExecutableResource.withHttpsDeveloperCertificate(options?: {
password?: string | ParameterResource;
} | undefined): NodeAppResource (+1 overload)

Indicates that a resource should use the developer certificate key pair for HTTPS endpoints at run time. Currently this indicates use of the ASP.NET Core developer certificate. The developer certificate will only be used when running in local development scenarios; in publish mode resources will use their default certificate configuration.

withHttpsDeveloperCertificate
() // Server cert for HTTPS endpoints
.
ExecutableResource.withDeveloperCertificateTrust(trust: boolean): NodeAppResource

Indicates whether developer certificates should be treated as trusted certificate authorities for the resource at run time. Currently this indicates trust for the ASP.NET Core developer certificate. The developer certificate will only be trusted when running in local development scenarios; in publish mode resources will use their default certificate trust.

withDeveloperCertificateTrust
(true); // Client trust for dashboard
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

When working with corporate or custom CA certificates, you can configure both server and client certificates:

AppHost.cs
using System.Security.Cryptography.X509Certificates;
var builder = DistributedApplication.CreateBuilder(args);
// Load custom certificates
var serverCert = new X509Certificate2("server-cert.pfx", "password");
var customCA = new X509Certificate2Collection();
customCA.Import("corporate-ca.pem");
var caBundle = builder.AddCertificateAuthorityCollection("corporate-certs")
.WithCertificates(customCA);
// Configure service with custom server cert and CA trust
builder.AddContainer("api", "my-api:latest")
.WithHttpsCertificate(serverCert) // Server cert for HTTPS
.WithCertificateAuthorityCollection(caBundle); // Trust corporate CA
builder.Build().Run();

Redis resources can be configured to use HTTPS (TLS) for secure connections:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
// Configure Redis to use the developer certificate for TLS
const
const redis: RedisResource
redis
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addRedis(name: string, options?: {
port?: number;
password?: string | ParameterResource;
}): RedisResource (+1 overload)

Adds a Redis container to the application model.

addRedis
("cache")
.
ContainerResource.withHttpsDeveloperCertificate(options?: {
password?: string | ParameterResource;
} | undefined): RedisResource (+1 overload)

Indicates that a resource should use the developer certificate key pair for HTTPS endpoints at run time. Currently this indicates use of the ASP.NET Core developer certificate. The developer certificate will only be used when running in local development scenarios; in publish mode resources will use their default certificate configuration.

withHttpsDeveloperCertificate
();
// Or disable TLS entirely
const
const redisNoTls: IResourceWithEnvironment
redisNoTls
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addRedis(name: string, options?: {
port?: number;
password?: string | ParameterResource;
}): RedisResource (+1 overload)

Adds a Redis container to the application model.

addRedis
("cache-notls")
.
ContainerResource.withoutHttpsCertificate(): IResourceWithEnvironment

Disable HTTPS/TLS server certificate configuration for the resource. No HTTPS/TLS termination configuration will be applied.

withoutHttpsCertificate
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

Disable certificate configuration for specific resources

Section titled “Disable certificate configuration for specific resources”

To disable both HTTPS endpoint configuration and certificate trust for a resource that manages its own certificates:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
,
type CertificateTrustScope = "None" | "Append" | "Override" | "System"
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
} from './.aspire/modules/aspire.mjs';
const
const builder: IDistributedApplicationBuilder
builder
= await
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

createBuilder
();
// Disable all automatic certificate configuration
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addPythonModule(name: string, appDirectory: string, moduleName: string): PythonAppResource

Adds a Python module to the application model.

addPythonModule
("api", "./api", "uvicorn")
.
ExecutableResource.withoutHttpsCertificate(): IResourceWithEnvironment

Disable HTTPS/TLS server certificate configuration for the resource. No HTTPS/TLS termination configuration will be applied.

withoutHttpsCertificate
() // No server cert config
.
IResourceWithEnvironment.withCertificateTrustScope(scope: CertificateTrustScope): IResourceWithEnvironment

Sets the certificate trust scope

withCertificateTrustScope
(
const CertificateTrustScope: {
readonly None: "None";
readonly Append: "Append";
readonly Override: "Override";
readonly System: "System";
}

Enum Aspire.Hosting.ApplicationModel.CertificateTrustScope

CertificateTrustScope
.
type None: "None"
None
); // No client trust config
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

build
().
DistributedApplication.run(cancellationToken?: cancellationToken): void

Runs the distributed application

run
();

Certificate configuration has the following limitations:

  • Currently supported only in run mode, not in publish mode
  • Not all languages and runtimes support all trust scope modes
  • Python applications don’t natively support Append mode for certificate trust
  • Custom certificate configuration requires appropriate runtime support within the resource
  • HTTPS endpoint APIs are marked as experimental (ASPIRECERTIFICATES001)