ResourceBuilderExtensions Methods
AsHttp2Service(IResourceBuilder<T>) Section titled AsHttp2Service(IResourceBuilder<T>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> AsHttp2Service<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .ClearContainerFilesSources(IResourceBuilder<T>) Section titled ClearContainerFilesSources(IResourceBuilder<T>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> ClearContainerFilesSources<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The resource builder instance with the container files source annotation applied.ExcludeFromManifest(IResourceBuilder<T>) Section titled ExcludeFromManifest(IResourceBuilder<T>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> ExcludeFromManifest<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .ExcludeFromMcp(IResourceBuilder<T>) Section titled ExcludeFromMcp(IResourceBuilder<T>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> ExcludeFromMcp<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .GetConnectionProperty(IResourceWithConnectionString, string) Section titled GetConnectionProperty(IResourceWithConnectionString, string)extensionReferencepublic static class ResourceBuilderExtensions{ public static ReferenceExpression GetConnectionProperty( this IResourceWithConnectionString resource, string key) { // ... }}Parameters
resourceIkeystringThe key of the connection property to retrieve. Cannot be null.Returns
ReferenceExpression The value associated with the specified connection property key.Remarks
GetEndpoint(IResourceBuilder<T>, string, NetworkIdentifier) Section titled GetEndpoint(IResourceBuilder<T>, string, NetworkIdentifier)extensionEndpointEndpointReference by name from the resource. These endpoints are declared either using ResourceBuilderExtensions.WithEndpoint or by launch settings (for project resources). The EndpointReference can be used to resolve the address of the endpoint in ResourceBuilderExtensions.WithEnvironment . public static class ResourceBuilderExtensions{ public static EndpointReference GetEndpoint<T>( this IResourceBuilder<T> builder, string name, NetworkIdentifier contextNetworkId) { // ... }}Parameters
builderInamestringThe name of the endpoint.contextNetworkId NetworkReturns
EndpointReference An EndpointReference that can be used to resolve the address of the endpoint after resource allocation has occurred.Remarks
GetEndpoint(IResourceBuilder<T>, string) Section titled GetEndpoint(IResourceBuilder<T>, string)extensionEndpointEndpointReference by name from the resource. These endpoints are declared either using ResourceBuilderExtensions.WithEndpoint or by launch settings (for project resources). The EndpointReference can be used to resolve the address of the endpoint in ResourceBuilderExtensions.WithEnvironment . public static class ResourceBuilderExtensions{ public static EndpointReference GetEndpoint<T>( this IResourceBuilder<T> builder, string name) { // ... }}Parameters
builderInamestringThe name of the endpoint.Returns
EndpointReference An EndpointReference that can be used to resolve the address of the endpoint after resource allocation has occurred.PublishWithContainerFiles(IResourceBuilder<T>, IResourceBuilder<IResourceWithContainerFiles>, string) Section titled PublishWithContainerFiles(IResourceBuilder<T>, IResourceBuilder<IResourceWithContainerFiles>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> PublishWithContainerFiles<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResourceWithContainerFiles> source, string destinationPath) { // ... }}Parameters
builderIsourceIResourceBuilder<IResourceWithContainerFiles> The resource which contains the container files to be copied.destinationPath stringThe destination path within the resource's container where the files will be copied.SubscribeHttpsEndpointsUpdate(IResourceBuilder<TResource>, Action<HttpsEndpointUpdateCallbackContext>) Section titled SubscribeHttpsEndpointsUpdate(IResourceBuilder<TResource>, Action<HttpsEndpointUpdateCallbackContext>)extensionIResourceBuilder<TResource> BeforeStartEvent and invokes the specified callback when an HTTPS certificate is determined to be available for the resource. This is used to conditionally update endpoint URI schemes or perform other HTTPS-related configuration at startup. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> SubscribeHttpsEndpointsUpdate<TResource>( this IResourceBuilder<TResource> builder, Action<HttpsEndpointUpdateCallbackContext> callback) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.callbackAction<HttpsEndpointUpdateCallbackContext> The callback to invoke when HTTPS is enabled. Receives an HttpsEndpointUpdateCallbackContext providing access to the service provider, resource, and application model.Returns
IResourceBuilder<TResource> The updated resource builder.Remarks
- No
Httpsis present and theCertificate Annotation Iindicates that HTTPS should be used by default.Developer Certificate Service - An
Httpsis present that requests a developer certificate or provides a custom certificate.Certificate Annotation
builder.SubscribeHttpsEndpointsUpdate(ctx =>{ builder.WithEndpoint("http", ep => ep.UriScheme = "https");});WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>) Section titled WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitFor<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency) { // ... }}Parameters
builderIdependencyIResourceBuilder<IResource> The resource builder for the dependency resource.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method is useful when a resource should wait until another has started running. This can help reduce errors in logs during local development where dependency resources.
Some resources automatically register health checks with the application host container. For these resources, calling Resource also results in the resource being blocked from starting until the health checks associated with the dependency resource return Health.
The Resource method can be used to associate additional health checks with a resource.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitFor(messaging);WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior) Section titled WaitFor(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitFor<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, WaitBehavior waitBehavior) { // ... }}Parameters
builderIdependencyIResourceBuilder<IResource> The resource builder for the dependency resource.waitBehavior WaitReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method is useful when a resource should wait until another has started running. This can help reduce errors in logs during local development where dependency resources.
Some resources automatically register health checks with the application host container. For these resources, calling Resource also results in the resource being blocked from starting until the health checks associated with the dependency resource return Health.
The Resource method can be used to associate additional health checks with a resource.
The wait parameter can be used to control the behavior of the wait operation. When Wait is specified, the wait operation will continue to wait until the resource becomes healthy. This is the default behavior with the Resource overload.
When Wait is specified, the wait operation will throw a Distributed if the resource enters an unavailable state.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitFor(messaging, WaitBehavior.StopOnResourceUnavailable);WaitForCompletion(IResourceBuilder<T>, IResourceBuilder<IResource>, int) Section titled WaitForCompletion(IResourceBuilder<T>, IResourceBuilder<IResource>, int)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitForCompletion<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, int exitCode = 0) { // ... }}Parameters
builderIdependencyIResourceBuilder<IResource> The resource builder for the dependency resource.exitCode intoptionalThe exit code which is interpreted as successful.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method is useful when a resource should wait until another has completed. A common usage pattern would be to include a console application that initializes the database schema or performs other one off initialization tasks.
Note that this method has no impact at deployment time and only works for local development.
Wait for database initialization app to complete running.var builder = DistributedApplication.CreateBuilder(args);var pgsql = builder.AddPostgres("postgres");var dbprep = builder.AddProject<Projects.DbPrepApp>("dbprep") .WithReference(pgsql);builder.AddProject<Projects.DatabasePrepTool>("dbpreptool") .WithReference(pgsql) .WaitForCompletion(dbprep);WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>) Section titled WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitForStart<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency) { // ... }}Parameters
builderIdependencyIResourceBuilder<IResource> The resource builder for the dependency resource.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method is useful when a resource should wait until another has started running but doesn't need to wait for health checks to pass. This can help enable initialization scenarios where services need to start before health checks can pass.
Unlike Resource, this method only waits for the dependency resource to enter the Running state and ignores any health check annotations associated with the dependency resource.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitForStart(messaging);WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior) Section titled WaitForStart(IResourceBuilder<T>, IResourceBuilder<IResource>, WaitBehavior)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WaitForStart<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> dependency, WaitBehavior waitBehavior) { // ... }}Parameters
builderIdependencyIResourceBuilder<IResource> The resource builder for the dependency resource.waitBehavior WaitReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method is useful when a resource should wait until another has started running but doesn't need to wait for health checks to pass. This can help enable initialization scenarios where services need to start before health checks can pass.
Unlike Resource, this method only waits for the dependency resource to enter the Running state and ignores any health check annotations associated with the dependency resource.
The wait parameter can be used to control the behavior of the wait operation. When Wait is specified, the wait operation will continue to wait until the resource enters the Running state. This is the default behavior with the Resource overload.
When Wait is specified, the wait operation will throw a Distributed if the resource enters an unavailable state.
var builder = DistributedApplication.CreateBuilder(args);var messaging = builder.AddRabbitMQ("messaging");builder.AddProject<Projects.MyApp>("myapp") .WithReference(messaging) .WaitForStart(messaging, WaitBehavior.StopOnResourceUnavailable);WithArgs(IResourceBuilder<T>, string[]) Section titled WithArgs(IResourceBuilder<T>, string[])extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, params string[] args) { // ... }}Parameters
builderIIResourceWithArgs .argsstring[]The arguments to be passed to the resource when it is started.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithArgs(IResourceBuilder<T>, object[]) Section titled WithArgs(IResourceBuilder<T>, object[])extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, params object[] args) { // ... }}Parameters
builderIIResourceWithArgs .argsobject[]The arguments to be passed to the resource when it is started.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>) Section titled WithArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, Action<CommandLineArgsCallbackContext> callback) { // ... }}Parameters
builderIIResourceWithArgs .callbackAction<CommandLineArgsCallbackContext> A callback that allows for deferred execution for computing arguments. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>) Section titled WithArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithArgs<T>( this IResourceBuilder<T> builder, Func<CommandLineArgsCallbackContext, Task> callback) { // ... }}Parameters
builderIIResourceWithArgs .callbackFunc<CommandLineArgsCallbackContext, Task> An asynchronous callback that allows for deferred execution for computing arguments. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithCertificateAuthorityCollection(IResourceBuilder<TResource>, IResourceBuilder<CertificateAuthorityCollection>) Section titled WithCertificateAuthorityCollection(IResourceBuilder<TResource>, IResourceBuilder<CertificateAuthorityCollection>)extensionIResourceBuilder<TResource> CertificateAuthorityCollectionAnnotation to the resource annotations to associate a certificate authority collection with the resource. This is used to configure additional trusted certificate authorities for the resource. Custom certificate trust is only applied in run mode; in publish mode resources will use their default certificate trust behavior. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithCertificateAuthorityCollection<TResource>( this IResourceBuilder<TResource> builder, IResourceBuilder<CertificateAuthorityCollection> certificateAuthorityCollection) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.certificateAuthorityCollection IResourceBuilder<CertificateAuthorityCollection> Additional certificates in a CertificateAuthorityCollection to treat as trusted certificate authorities for the resource.Returns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
var caCollection = builder.AddCertificateAuthorityCollection("my-cas") .WithCertificatesFromFile("../my-ca.pem");
var container = builder.AddContainer("my-service", "my-service:latest") .WithCertificateAuthorityCollection(caCollection);This method is not available in polyglot AppHosts.
WithCertificateTrustConfiguration(IResourceBuilder<TResource>, Func<CertificateTrustConfigurationCallbackAnnotationContext, Task>) Section titled WithCertificateTrustConfiguration(IResourceBuilder<TResource>, Func<CertificateTrustConfigurationCallbackAnnotationContext, Task>)extensionIResourceBuilder<TResource> CertificateTrustConfigurationCallbackAnnotation to the resource annotations to associate a callback that is invoked when a resource needs to configure itself for custom certificate trust. May be called multiple times to register additional callbacks to append additional configuration. Custom certificate trust is only applied in run mode; in publish mode resources will use their default certificate trust behavior. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithCertificateTrustConfiguration<TResource>( this IResourceBuilder<TResource> builder, Func<CertificateTrustConfigurationCallbackAnnotationContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.callbackFunc<CertificateTrustConfigurationCallbackAnnotationContext, Task> The callback to invoke when a resource needs to configure itself for custom certificate trust.Returns
IResourceBuilder<TResource> The updated resource builder.Remarks
var container = builder.AddContainer("my-service", "my-service:latest") .WithCertificateTrustConfigurationCallback(ctx => { if (ctx.Scope != CertificateTrustScope.Append) { ctx .EnvironmentVariables["CUSTOM_CERTS_BUNDLE_ENV"] = ctx .CertificateBundlePath; } ctx .EnvironmentVariables["ADDITIONAL_CERTS_DIR_ENV"] = ctx .CertificateDirectoriesPath; });This method is not available in polyglot AppHosts.
WithCertificateTrustScope(IResourceBuilder<TResource>, CertificateTrustScope) Section titled WithCertificateTrustScope(IResourceBuilder<TResource>, CertificateTrustScope)extensionIResourceBuilder<TResource> CertificateTrustScope for custom certificate authorities associated with the resource. The scope specifies how custom certificate authorities should be applied to a resource at run time in local development scenarios. Custom certificate trust is only applied in run mode; in publish mode resources will use their default certificate trust behavior. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithCertificateTrustScope<TResource>( this IResourceBuilder<TResource> builder, CertificateTrustScope scope) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.scopeCertificateReturns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
CertificateTrustScope.Append which means that custom certificate authorities should be appended to the default trusted certificate authorities for the resource. Setting the scope to CertificateTrustScope.Override indicates the set of certificates in referenced CertificateAuthorityCollection (and optionally Aspire developer certificiates) should be used as the exclusive source of trust for a resource. In all cases, this is a best effort implementation as not all resources support full customization of certificate trust. Set the scope for custom certificate authorities to override the default trusted certificate authorities for a container resource. var caCollection = builder.AddCertificateAuthorityCollection("my-cas") .WithCertificate(new X509Certificate2("my-ca.pem"));
var container = builder.AddContainer("my-service", "my-service:latest") .WithCertificateAuthorityCollection(caCollection) .WithCertificateTrustScope(CertificateTrustScope.Override);WithChildRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>) Section titled WithChildRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithChildRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> child) { // ... }}Parameters
builderIchildIResourceBuilder<IResource> The child of builder.Returns
IResourceBuilder<T> A resource builder.Remarks
The With method is used to add child relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);
var parameter = builder.AddParameter("parameter");
var backend = builder.AddProject<Projects.Backend>("backend"); .WithChildRelationship(parameter);WithChildRelationship(IResourceBuilder<T>, IResource) Section titled WithChildRelationship(IResourceBuilder<T>, IResource)extensionIResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithChildRelationship<T>( this IResourceBuilder<T> builder, IResource child) { // ... }}Parameters
builderIchildIbuilder.Returns
IResourceBuilder<T> A resource builder.Remarks
The With method is used to add child relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);
var parameter = builder.AddParameter("parameter");
var backend = builder.AddProject<Projects.Backend>("backend"); .WithChildRelationship(parameter.Resource);This method is not available in polyglot AppHosts. Use the IResourceBuilder overload instead.
WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, CommandOptions?) Section titled WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, CommandOptions?)extensionIResourceCommandAnnotation to the resource annotations to add a resource command. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithCommand<T>( this IResourceBuilder<T> builder, string name, string displayName, Func<ExecuteCommandContext, Task<ExecuteCommandResult>> executeCommand, CommandOptions? commandOptions = null) { // ... }}Parameters
builderInamestringThe name of the command. The name uniquely identifies the command.displayName stringThe display name visible in UI.executeCommand Func<ExecuteCommandContext, Task<ExecuteCommandResult>> A callback that is executed when the command is executed. The callback is run inside the Aspire host. The callback result is used to indicate success or failure in the UI. commandOptions CommandReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
The With method is used to add commands to the resource. Commands are displayed in the dashboard and can be executed by a user using the dashboard UI.
When a command is executed, the execute callback is called and is run inside the Aspire host.
WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, Func<UpdateCommandStateContext, ResourceCommandState>, string?, object?, string?, string?, IconVariant?, bool) Section titled WithCommand(IResourceBuilder<T>, string, string, Func<ExecuteCommandContext, Task<ExecuteCommandResult>>, Func<UpdateCommandStateContext, ResourceCommandState>, string?, object?, string?, string?, IconVariant?, bool)extensionIResourceCommandAnnotation to the resource annotations to add a resource command. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithCommand<T>( this IResourceBuilder<T> builder, string name, string displayName, Func<ExecuteCommandContext, Task<ExecuteCommandResult>> executeCommand, Func<UpdateCommandStateContext, ResourceCommandState>? updateState = null, string? displayDescription = null, object? parameter = null, string? confirmationMessage = null, string? iconName = null, IconVariant? iconVariant = null, bool isHighlighted = false) { // ... }}Parameters
builderInamestringThe name of the command. The name uniquely identifies the command.displayName stringThe display name visible in UI.executeCommand Func<ExecuteCommandContext, Task<ExecuteCommandResult>> A callback that is executed when the command is executed. The callback is run inside the Aspire host. The callback result is used to indicate success or failure in the UI. updateState Func<UpdateCommandStateContext, ResourceCommandState> optionalA callback that is used to update the command state. The callback is executed when the command's resource snapshot is updated.
If a callback isn't specified, the command is always enabled.
displayDescription string?optional Optional description of the command, to be shown in the UI. Could be used as a tooltip. May be localized. parameterobject?optional Optional parameter that configures the command in some way. Clients must return any value provided by the server when invoking the command. confirmationMessage string?optional When a confirmation message is specified, the UI will prompt with an OK/Cancel dialog and the confirmation message before starting the command. iconName string?optionalThe icon name for the command. The name should be a valid FluentUI icon name from https://aka.ms/fluentui-system-iconsiconVariant IconisHighlighted booloptionalA flag indicating whether the command is highlighted in the UI.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
The With method is used to add commands to the resource. Commands are displayed in the dashboard and can be executed by a user using the dashboard UI.
When a command is executed, the execute callback is called and is run inside the Aspire host.
WithComputeEnvironment(IResourceBuilder<T>, IResourceBuilder<IComputeEnvironmentResource>) Section titled WithComputeEnvironment(IResourceBuilder<T>, IResourceBuilder<IComputeEnvironmentResource>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithComputeEnvironment<T>( this IResourceBuilder<T> builder, IResourceBuilder<IComputeEnvironmentResource> computeEnvironmentResource) { // ... }}Parameters
builderIcomputeEnvironmentResource IResourceBuilder<IComputeEnvironmentResource> The compute environment resource to associate with the compute resource.Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
WithConnectionProperty(IResourceBuilder<T>, string, ReferenceExpression) Section titled WithConnectionProperty(IResourceBuilder<T>, string, ReferenceExpression)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithConnectionProperty<T>( this IResourceBuilder<T> builder, string name, ReferenceExpression value) { // ... }}Parameters
builderInamestringThe name of the connection property to annotate. Cannot be null.valueReferenceReturns
IResourceBuilder<T> The same resource builder instance with the connection property annotation applied.Remarks
WithConnectionProperty(IResourceBuilder<T>, string, string) Section titled WithConnectionProperty(IResourceBuilder<T>, string, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithConnectionProperty<T>( this IResourceBuilder<T> builder, string name, string value) { // ... }}Parameters
builderInamestringThe name of the connection property to add. Cannot be null.valuestringThe value to assign to the connection property.Returns
IResourceBuilder<T> The same resource builder instance with the specified connection property annotation applied.WithConnectionStringRedirection(IResourceBuilder<T>, IResourceWithConnectionString) Section titled WithConnectionStringRedirection(IResourceBuilder<T>, IResourceWithConnectionString)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithConnectionStringRedirection<T>( this IResourceBuilder<T> builder, IResourceWithConnectionString resource) { // ... }}Parameters
builderIresourceIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithContainerFilesSource(IResourceBuilder<T>, string) Section titled WithContainerFilesSource(IResourceBuilder<T>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithContainerFilesSource<T>( this IResourceBuilder<T> builder, string sourcePath) { // ... }}Parameters
builderIsourcePath stringThe path to the container files source to associate with the resource. Cannot be null.Returns
IResourceBuilder<T> The resource builder instance with the container files source annotation applied.WithDebugSupport(IResourceBuilder<T>, Func<string, TLaunchConfiguration>, string) Section titled WithDebugSupport(IResourceBuilder<T>, Func<string, TLaunchConfiguration>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithDebugSupport<T, TLaunchConfiguration>( this IResourceBuilder<T> builder, Func<string, TLaunchConfiguration> launchConfigurationProducer, string launchConfigurationType) { // ... }}Parameters
builderIlaunchConfigurationProducer Func<string, TLaunchConfiguration> A callback that receives the launch mode and produces the complete launch configuration handed to the IDE.launchConfigurationType stringThe type tag of the launch configuration sent to the IDE.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentExceptionTLaunchConfiguration is a Tasks.Task or Tasks.ValueTask . Use an asynchronous overload instead so the task result, rather than the task itself, becomes the launch configuration. Remarks
launchConfigurationProducer later only for executable creations where this debug-support annotation is active, including restarts and replicas. The callback does not run for unsupported debug sessions, publish mode, or inactive annotations superseded by a later SupportsDebuggingAnnotation . WithDebugSupport(IResourceBuilder<T>, Func<string, CancellationToken, Task<TLaunchConfiguration>>, string) Section titled WithDebugSupport(IResourceBuilder<T>, Func<string, CancellationToken, Task<TLaunchConfiguration>>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithDebugSupport<T, TLaunchConfiguration>( this IResourceBuilder<T> builder, Func<string, CancellationToken, Task<TLaunchConfiguration>> launchConfigurationProducer, string launchConfigurationType) { // ... }}Parameters
builderIlaunchConfigurationProducer Func<string, CancellationToken, Task<TLaunchConfiguration>> A callback that receives the launch mode and cancellation token.launchConfigurationType stringThe type tag of the launch configuration sent to the IDE.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithDebugSupport(IResourceBuilder<T>, Func<LaunchConfigurationCallbackContext, Task<TLaunchConfiguration>>, string) Section titled WithDebugSupport(IResourceBuilder<T>, Func<LaunchConfigurationCallbackContext, Task<TLaunchConfiguration>>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithDebugSupport<T, TLaunchConfiguration>( this IResourceBuilder<T> builder, Func<LaunchConfigurationCallbackContext, Task<TLaunchConfiguration>> launchConfigurationProducer, string launchConfigurationType) { // ... }}Parameters
builderIlaunchConfigurationProducer Func<LaunchConfigurationCallbackContext, Task<TLaunchConfiguration>> A callback that receives the resolved environment variables and asynchronously produces the complete launch configuration handed to the IDE. launchConfigurationType stringThe type tag of the launch configuration sent to the IDE.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
launchConfigurationProducer after resolving the execution configuration for each executable creation. A producer that completes synchronously should return its result with Task.FromResult . Process execution does not generally require a producer, but Aspire can still invoke a supported non- project producer for a process executable so it can contribute launch metadata. Examples
Produce a launch configuration using a resolved environment variable:
internal sealed class MyToolLaunchConfiguration() : ExecutableLaunchConfiguration("mytool"){ public string? TargetDirectory { get; set; }}
builder.AddExecutable("tool", "mytool", ".") .WithDebugSupport( context => { context.EnvironmentVariables.TryGetValue("MYTOOL_TARGET_DIR", out var targetDirectory); return Task.FromResult(new MyToolLaunchConfiguration { Mode = context.Mode, TargetDirectory = targetDirectory }); }, launchConfigurationType: "mytool");WithDeveloperCertificateTrust(IResourceBuilder<TResource>, bool) Section titled WithDeveloperCertificateTrust(IResourceBuilder<TResource>, bool)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithDeveloperCertificateTrust<TResource>( this IResourceBuilder<TResource> builder, bool trust) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.trustboolIndicates whether the developer certificate should be treated as trusted.Returns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
var container = builder.AddContainer("my-service", "my-service:latest") .WithDeveloperCertificateTrust(false);var builder = DistributedApplication.CreateBuilder( new DistributedApplicationOptions(){ Args = args, TrustDeveloperCertificate = false,});var project = builder.AddProject<MyService>("my-service") .WithDeveloperCertificateTrust(true);WithEndpoint(IResourceBuilder<T>, string, Action<EndpointAnnotation>, bool) Section titled WithEndpoint(IResourceBuilder<T>, string, Action<EndpointAnnotation>, bool)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, string endpointName, Action<EndpointAnnotation> callback, bool createIfNotExists = true) { // ... }}Parameters
builderIendpointName stringName of endpoint to change.callbackAction<EndpointAnnotation> Callback that modifies the endpoint.createIfNotExists booloptionalCreate endpoint if it does not exist.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
The Resource method allows developers to mutate any aspect of an endpoint annotation. Note that changing one value does not automatically change other values to compatible/consistent values. For example setting the Endpoint property of the endpoint annotation in the callback will not automatically change the Endpoint. All values should be set in the callback if the defaults are not acceptable.
var builder = DistributedApplication.Create(args);var container = builder.AddContainer("mycontainer", "myimage") .WithEndpoint("myendpoint", e => { e.Port = 9998; e.TargetPort = 9999; e.Protocol = ProtocolType.Udp; e.UriScheme = "udp"; });This method is not available in polyglot AppHosts. Use the callback-based endpoint mutation export instead.
WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?, ProtocolType?) Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?, ProtocolType?)extensionIResourceBuilderExtensions.GetEndpoint . The endpoint name will be the scheme name if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port = null, int? targetPort = null, string? scheme = null, string? name = null, string? env = null, bool? isProxied = null, bool? isExternal = null, ProtocolType? protocol = null) { // ... }}Parameters
builderIportint?optionalAn optional port. This is the port that will be given to other resource to communicate with this resource.targetPort int?optionalThis is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?optionalAn optional scheme e.g. (http/https). Defaults to the protocol argument if it is defined or "tcp" otherwise.namestring?optionalAn optional name of the endpoint. Defaults to the scheme name if not specified.envstring?optionalAn optional name of the environment variable that will be used to inject the targetPort . If the target port is null one will be dynamically generated and assigned to the environment variable.isProxied bool?optionalSpecifies if the endpoint will be proxied by DCP. Defaults to null.isExternal bool?optionalIndicates that this endpoint should be exposed externally at publish time.protocolProtocolType? optionalNetwork protocol: TCP or UDP are supported today, others possibly in future.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?, ProtocolType?) Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?, ProtocolType?)extensionIResourceBuilderExtensions.GetEndpoint . public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? scheme, string? name, string? env, bool isProxied, bool? isExternal, ProtocolType? protocol) { // ... }}Parameters
builderIportint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPort int?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?An optional scheme e.g. (http/https). Defaults to the protocol argument if it is defined or "tcp" otherwise.namestring?An optional name of the endpoint. Defaults to the scheme name if not specified.envstring?An optional name of the environment variable that will be used to inject the targetPort . If the target port is null one will be dynamically generated and assigned to the environment variable.isProxied boolSpecifies if the endpoint will be proxied by DCP.isExternal bool?Indicates that this endpoint should be exposed externally at publish time.protocolProtocolType? Network protocol: TCP or UDP are supported today, others possibly in future.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?) Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool?, bool?)extensionIResourceBuilderExtensions.GetEndpoint . The endpoint name will be the scheme name if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? scheme, string? name, string? env, bool? isProxied, bool? isExternal) { // ... }}Parameters
builderIportint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPort int?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?An optional scheme e.g. (http/https). Defaults to "tcp" if not specified.namestring?An optional name of the endpoint. Defaults to the scheme name if not specified.envstring?An optional name of the environment variable that will be used to inject the targetPort . If the target port is null one will be dynamically generated and assigned to the environment variable.isProxied bool?Specifies if the endpoint will be proxied by DCP. Defaults to null.isExternal bool?Indicates that this endpoint should be exposed externally at publish time.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.Remarks
This method is not available in polyglot AppHosts. Use the overload with ProtocolType parameter instead.
If an endpoint with the same name already exists, the existing endpoint is updated with any non-null parameter values.
WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?) Section titled WithEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, string?, bool, bool?)extensionIResourceBuilderExtensions.GetEndpoint . The endpoint name will be the scheme name if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? scheme, string? name, string? env, bool isProxied, bool? isExternal) { // ... }}Parameters
builderIportint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPort int?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.schemestring?An optional scheme e.g. (http/https). Defaults to "tcp" if not specified.namestring?An optional name of the endpoint. Defaults to the scheme name if not specified.envstring?An optional name of the environment variable that will be used to inject the targetPort . If the target port is null one will be dynamically generated and assigned to the environment variable.isProxied boolSpecifies if the endpoint will be proxied by DCP.isExternal bool?Indicates that this endpoint should be exposed externally at publish time.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
DistributedApplicationExceptionThrows an exception if an endpoint with the same name already exists on the specified resource.Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithEndpointProxySupport(IResourceBuilder<IResourceWithEndpoints>, bool) Section titled WithEndpointProxySupport(IResourceBuilder<IResourceWithEndpoints>, bool)extensionIResourceBuilder<IResourceWithEndpoints> false, endpoints belonging to the resource will ignore the configured proxy settings and run proxy-less. public static class ResourceBuilderExtensions{ public static IResourceBuilder<IResourceWithEndpoints> WithEndpointProxySupport( this IResourceBuilder<IResourceWithEndpoints> builder, bool proxyEnabled) { // ... }}Parameters
builderIResourceBuilder<IResourceWithEndpoints> The resource builder.proxyEnabled boolShould endpoints for the resource support using a proxy?Returns
IResourceBuilder<IResourceWithEndpoints> The resource builder.Remarks
WithEnvironment(IResourceBuilder<T>, string, string?) Section titled WithEnvironment(IResourceBuilder<T>, string, string?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, string? value) { // ... }}Parameters
builderInamestringThe name of the environment variable.valuestring?The value of the environment variable.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithEnvironment(IResourceBuilder<T>, string, ExpressionInterpolatedStringHandler) Section titled WithEnvironment(IResourceBuilder<T>, string, ExpressionInterpolatedStringHandler)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, in ExpressionInterpolatedStringHandler value) { // ... }}Parameters
builderInamestringThe name of the environment variable.valueExpressionReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithEnvironment(IResourceBuilder<T>, string, ReferenceExpression) Section titled WithEnvironment(IResourceBuilder<T>, string, ReferenceExpression)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, ReferenceExpression value) { // ... }}Parameters
builderInamestringThe name of the environment variable.valueReferenceReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This overload enables polyglot hosts to set environment variables using dynamic expressions that reference endpoints, parameters, and other value providers.
Usage from TypeScript:
WithEnvironment(IResourceBuilder<T>, string, Func<string>) Section titled WithEnvironment(IResourceBuilder<T>, string, Func<string>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, Func<string> callback) { // ... }}Parameters
builderInamestringThe name of the environment variable.callbackFunc<string> A callback that allows for deferred execution of a specific environment variable. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithEnvironment(IResourceBuilder<T>, Action<EnvironmentCallbackContext>) Section titled WithEnvironment(IResourceBuilder<T>, Action<EnvironmentCallbackContext>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, Action<EnvironmentCallbackContext> callback) { // ... }}Parameters
builderIcallbackAction<EnvironmentCallbackContext> A callback that allows for deferred execution for computing many environment variables. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>) Section titled WithEnvironment(IResourceBuilder<T>, Func<EnvironmentCallbackContext, Task>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, Func<EnvironmentCallbackContext, Task> callback) { // ... }}Parameters
builderIcallbackFunc<EnvironmentCallbackContext, Task> A callback that allows for deferred execution for computing many environment variables. This runs after resources have been allocated by the orchestrator and allows access to other resources to resolve computed data, e.g. connection strings, ports.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithEnvironment(IResourceBuilder<T>, string, EndpointReference) Section titled WithEnvironment(IResourceBuilder<T>, string, EndpointReference)extensionIendpointReference . public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, EndpointReference endpointReference) { // ... }}Parameters
builderInamestringThe name of the environment variable.endpointReference EndpointReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ExternalServiceResource>) Section titled WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ExternalServiceResource>)extensionIExternalServiceResource . public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, IResourceBuilder<ExternalServiceResource> externalService) { // ... }}Parameters
builderInamestringThe name of the environment variable.externalService IResourceBuilder<ExternalServiceResource> The external service.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>) Section titled WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<ParameterResource>)extensionIparameter. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, IResourceBuilder<ParameterResource> parameter) { // ... }}Parameters
builderInamestringName of environment variable.parameterIResourceBuilder<ParameterResource> Resource builder for the parameter resource.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<IResourceWithConnectionString>) Section titled WithEnvironment(IResourceBuilder<T>, string, IResourceBuilder<IResourceWithConnectionString>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string envVarName, IResourceBuilder<IResourceWithConnectionString> resource) { // ... }}Parameters
builderIenvVarName stringThe name of the environment variable under which the connection string will be set.resourceIResourceBuilder<IResourceWithConnectionString> The resource builder of the referenced service from which to pull the connection string.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithEnvironment(IResourceBuilder<T>, string, IExpressionValue) Section titled WithEnvironment(IResourceBuilder<T>, string, IExpressionValue)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T>( this IResourceBuilder<T> builder, string name, IExpressionValue value) { // ... }}Parameters
builderInamestringThe name of the environment variable.valueIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
withEnvironment overload instead.WithEnvironment(IResourceBuilder<T>, string, TValue) Section titled WithEnvironment(IResourceBuilder<T>, string, TValue)extensionIIValueProvider and IManifestExpressionProvider . public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithEnvironment<T, TValue>( this IResourceBuilder<T> builder, string name, TValue value) { // ... }}Parameters
builderInamestringThe name of the environment variable.valueTValue The value that provides both runtime values and manifest expressions.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithExplicitStart(IResourceBuilder<T>) Section titled WithExplicitStart(IResourceBuilder<T>)extensionIExplicitStartupAnnotation annotation to the resource so it doesn't automatically start with the AppHost startup. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithExplicitStart<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method is useful when a resource shouldn't automatically start when the AppHost starts.
The database clean up tool project isn't started with the AppHost. The resource start command can be used to run it ondemand later.var builder = DistributedApplication.CreateBuilder(args);var pgsql = builder.AddPostgres("postgres");builder.AddProject<Projects.CleanUpDatabase>("dbcleanuptool") .WithReference(pgsql) .WithExplicitStart();WithExternalHttpEndpoints(IResourceBuilder<T>) Section titled WithExternalHttpEndpoints(IResourceBuilder<T>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithExternalHttpEndpoints<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .WithHealthCheck(IResourceBuilder<T>, string) Section titled WithHealthCheck(IResourceBuilder<T>, string)extensionIHealthCheckAnnotation to the resource annotations to associate a resource with a named health check managed by the health check service. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHealthCheck<T>( this IResourceBuilder<T> builder, string key) { // ... }}Parameters
builderIkeystringThe key for the health check.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
The Resource method is used in conjunction with the Resource to associate a resource registered in the application hosts dependency injection container. The Resource method does not inject the health check itself it is purely an association mechanism.
var builder = DistributedApplication.CreateBuilder(args);
var startAfter = DateTime.Now.AddSeconds(30);
builder.Services.AddHealthChecks().AddCheck(mycheck", () =>{ return DateTime.Now > startAfter ? HealthCheckResult.Healthy( ) : HealthCheckResult.Unhealthy();});
var pg = builder.AddPostgres("pg") .WithHealthCheck("mycheck");
builder.AddProject<Projects.MyApp>("myapp") .WithReference(pg) .WaitFor( pg); // This will result in waiting for the building check, and the // custom check defined in the code.WithHttpCommand(IResourceBuilder<TResource>, string, string, string?, string?, HttpCommandOptions?) Section titled WithHttpCommand(IResourceBuilder<TResource>, string, string, string?, string?, HttpCommandOptions?)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpCommand<TResource>( this IResourceBuilder<TResource> builder, string path, string displayName, string? endpointName = null, string? commandName = null, HttpCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.pathstringThe path to send the request to when the command is invoked.displayName stringThe display name visible in UI.endpointName string?optionalThe name of the HTTP endpoint on this resource to send the request to when the command is invoked.commandName string?optionalOptional name of the command. The name uniquely identifies the command. If a name isn't specified then it's inferred using the command's endpoint and HTTP method.commandOptions HttpReturns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
The command will be added to the resource represented by builder.
If endpoint is specified, the request will be sent to the endpoint with that name on the resource represented by builder. If an endpoint with that name is not found, or the endpoint with that name is not an HTTP endpoint, an exception will be thrown.
If no endpoint is specified, the first HTTP endpoint found on the resource will be used. HTTP endpoints with an https scheme are preferred over those with an http scheme. If no HTTP endpoint is found on the resource, an exception will be thrown.
The command will not be enabled until the endpoint is allocated and the resource the endpoint is associated with is healthy.
If Http is not specified, POST will be used.
Specifying Http will use that named Http. when sending the request. This allows you to configure the Http. instance with a specific handler, timeout, or other options using Http. If Http is not specified, the default Http. will be used and its Http will be set to Timeout.. Specify a named client to preserve its configured timeout.
The Http callback will be invoked to configure the request before it is sent. This can be used to add headers or a request payload before the request is sent.
The Http callback will be invoked after the response is received to determine the result of the command invocation. If this callback is not specified, the command will be considered successful if the response status code is in the 2xx range. Set Http to flow the HTTP response body back to the command caller.
/clear-cache . var apiService = builder.AddProject>MyApiService>("api") .WithHttpCommand("/clear-cache", "Clear cache");/reset-db on endpoint named admin. The request's headers are configured to include an X-Admin-Key header for verification. var adminKey = builder.AddParameter("admin-key");var apiService = builder.AddProject>MyApiService>("api") .WithHttpsEndpoint("admin") .WithEnvironment("ADMIN_KEY", adminKey) .WithHttpCommand("/reset-db", "Reset database", endpointName: "admin", commandOptions: new () { Method = HttpMethod.Get, ConfirmationMessage = "Are you sure you want to reset the database?", PrepareRequest: request => { request.Headers.Add("X-Admin-Key", adminKey); return Task.CompletedTask; } });This method is not available in polyglot AppHosts.
WithHttpCommand(IResourceBuilder<TResource>, string, string, Func<EndpointReference>, string?, HttpCommandOptions?) Section titled WithHttpCommand(IResourceBuilder<TResource>, string, string, Func<EndpointReference>, string?, HttpCommandOptions?)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpCommand<TResource>( this IResourceBuilder<TResource> builder, string path, string displayName, Func<EndpointReference>? endpointSelector, string? commandName = null, HttpCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.pathstringThe path to send the request to when the command is invoked.displayName stringThe display name visible in UI.endpointSelector Func<EndpointReference> A callback that selects the HTTP endpoint to send the request to when the command is invoked.commandName string?optionalThe name of command. The name uniquely identifies the command.commandOptions HttpReturns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Exceptions
Remarks
The command will be added to the resource represented by builder.
If no Http is specified, the first HTTP endpoint found on the resource will be used. HTTP endpoints with an https scheme are preferred over those with an http scheme. If no HTTP endpoint is found on the resource, an exception will be thrown.
The supplied Http may return an endpoint from a different resource to that which the command is being added to.
The command will not be enabled until the endpoint is allocated and the resource the endpoint is associated with is healthy.
If Http is not specified, POST will be used.
Specifying a Http will use that named Http. when sending the request. This allows you to configure the Http. instance with a specific handler, timeout, or other options using Http. If Http is not specified, the default Http. will be used and its Http will be set to Timeout.. Specify a named client to preserve its configured timeout.
The Http callback will be invoked to configure the request before it is sent. This can be used to add headers or a request payload before the request is sent.
The Http callback will be invoked after the response is received to determine the result of the command invocation. If this callback is not specified, the command will be considered successful if the response status code is in the 2xx range. Set Http to flow the HTTP response body back to the command caller.
var loadGenerator = builder.AddProject>LoadGenerator>("load");var loadGeneratorEndpoint = loadGenerator.GetEndpoint("https");var customerService = builder.AddProject>CustomerService>("customer-service") .WithHttpCommand( "/stress?resource=customer-service&requests=1000", "Apply load (1000)", endpointSelector: () => loadGeneratorEndpoint) .WithHttpCommand( "/stress?resource=customer-service&requests=5000", "Apply load (5000)", endpointSelector: () => loadGeneratorEndpoint);loadGenerator.WithReference(customerService);This method is not available in polyglot AppHosts.
WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?) Section titled WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?)extensionIResourceBuilderExtensions.GetEndpoint . The endpoint name will be "http" if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpEndpoint<T>( this IResourceBuilder<T> builder, int? port = null, int? targetPort = null, string? name = null, string? env = null, bool? isProxied = null) { // ... }}Parameters
builderIportint?optionalAn optional port. This is the port that will be given to other resource to communicate with this resource.targetPort int?optionalThis is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?optionalAn optional name of the endpoint. Defaults to "http" if not specified.envstring?optionalAn optional name of the environment variable to inject.isProxied bool?optionalSpecifies if the endpoint will be proxied by DCP. Defaults to null.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
null will not modify the existing endpoint's values. WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool) Section titled WithHttpEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? name, string? env, bool isProxied) { // ... }}Parameters
builderIportint?An optional port. This is the port that will be given to other resource to communicate with this resource.targetPort int?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?An optional name of the endpoint. Defaults to "http" if not specified.envstring?An optional name of the environment variable to inject.isProxied boolSpecifies if the endpoint will be proxied by DCP.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithHttpHealthCheck(IResourceBuilder<T>, string?, int?, string?) Section titled WithHttpHealthCheck(IResourceBuilder<T>, string?, int?, string?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpHealthCheck<T>( this IResourceBuilder<T> builder, string? path = null, int? statusCode = null, string? endpointName = null) { // ... }}Parameters
builderIpathstring?optionalThe relative path to test.statusCode int?optionalThe result code to interpret as healthy.endpointName string?optionalThe name of the endpoint to derive the base address from.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method adds a health check to the health check service which polls the specified endpoint on the resource on a periodic basis. The base address is dynamically determined based on the endpoint that was selected. By default the path is set to "/" and the status code is set to 200.
This example shows adding an HTTP health check to a backend project. The health check makes sure that the front end does not start until the backend is reporting a healthy status based on the return code returned from the "/health" path on the backend server.var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend") .WithHttpHealthCheck("/health");builder.AddProject<Projects.Frontend>("frontend") .WithReference(backend).WaitFor(backend);WithHttpHealthCheck(IResourceBuilder<T>, Func<EndpointReference>, string?, int?) Section titled WithHttpHealthCheck(IResourceBuilder<T>, Func<EndpointReference>, string?, int?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpHealthCheck<T>( this IResourceBuilder<T> builder, Func<EndpointReference>? endpointSelector, string? path = null, int? statusCode = null) { // ... }}Parameters
builderIendpointSelector Func<EndpointReference> pathstring?optionalThe relative path to test.statusCode int?optionalThe result code to interpret as healthy.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method adds a health check to the health check service which polls the specified endpoint on a periodic basis. The base address is dynamically determined based on the endpoint that was selected. By default the path is set to "/" and the status code is set to 200.
This example shows adding an HTTP health check to a backend project. The health check makes sure that the front end does not start until the backend is reporting a healthy status based on the return code returned from the "/health" path on the backend server.var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");backend.WithHttpHealthCheck(() => backend.GetEndpoint("https"), path: "/health")builder.AddProject<Projects.Frontend>("frontend") .WithReference(backend).WaitFor(backend);This method is not available in polyglot AppHosts. Use the endpointName-based overload instead.
WithHttpProbe(IResourceBuilder<T>, ProbeType, string?, int?, int?, int?, int?, int?, string?) Section titled WithHttpProbe(IResourceBuilder<T>, ProbeType, string?, int?, int?, int?, int?, int?, string?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpProbe<T>( this IResourceBuilder<T> builder, ProbeType type, string? path = null, int? initialDelaySeconds = null, int? periodSeconds = null, int? timeoutSeconds = null, int? failureThreshold = null, int? successThreshold = null, string? endpointName = null) { // ... }}Parameters
builderItypeProbepathstring?optionalThe path to be used.initialDelaySeconds int?optionalThe initial delay before calling the probe endpoint for the first time.periodSeconds int?optionalThe period between each probe.timeoutSeconds int?optionalNumber of seconds after which the probe times out.failureThreshold int?optionalNumber of failures in a row before considers that the overall check has failed.successThreshold int?optionalMinimum consecutive successes for the probe to be considered successful after having failed.endpointName string?optionalThe name of the endpoint to be used for the probe.Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
This method allows you to specify a probe and implicit adds an http health check to the resource based on probe parameters.
For example add a probe to a resource in this way:var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health");var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health") .WithHttpHealthCheck("/health");This method is not available in polyglot AppHosts. The parameter name 'type' is a reserved keyword in Go and Rust.
WithHttpProbe(IResourceBuilder<T>, ProbeType, Func<EndpointReference>, string?, int?, int?, int?, int?, int?) Section titled WithHttpProbe(IResourceBuilder<T>, ProbeType, Func<EndpointReference>, string?, int?, int?, int?, int?, int?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpProbe<T>( this IResourceBuilder<T> builder, ProbeType type, Func<EndpointReference>? endpointSelector, string? path = null, int? initialDelaySeconds = null, int? periodSeconds = null, int? timeoutSeconds = null, int? failureThreshold = null, int? successThreshold = null) { // ... }}Parameters
builderItypeProbeendpointSelector Func<EndpointReference> The selector used to get endpoint reference.pathstring?optionalThe path to be used.initialDelaySeconds int?optionalThe initial delay before calling the probe endpoint for the first time.periodSeconds int?optionalThe period between each probe.timeoutSeconds int?optionalNumber of seconds after which the probe times out.failureThreshold int?optionalNumber of failures in a row before considers that the overall check has failed.successThreshold int?optionalMinimum consecutive successes for the probe to be considered successful after having failed.Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
This method allows you to specify a probe and implicit adds an http health check to the resource based on probe parameters.
For example add a probe to a resource in this way:var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health");var service = builder.AddProject<Projects.MyService>("service") .WithHttpProbe(ProbeType.Liveness, "/health") .WithHttpHealthCheck("/health");This method is not available in polyglot AppHosts. Use the endpointName-based overload instead.
WithHttpsCertificate(IResourceBuilder<TResource>, X509Certificate2, IResourceBuilder<ParameterResource>) Section titled WithHttpsCertificate(IResourceBuilder<TResource>, X509Certificate2, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<TResource> HttpsCertificateAnnotation to the resource annotations to associate an X.509 certificate key pair with the resource. This is used to configure the certificate presented by the resource for HTTPS/TLS endpoints. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpsCertificate<TResource>( this IResourceBuilder<TResource> builder, X509Certificate2 certificate, IResourceBuilder<ParameterResource>? password = null) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.certificateX509Certificate2 An X509Certificates.X509Certificate2 key pair to use for HTTPS/TLS endpoints on the resource.passwordIResourceBuilder<ParameterResource> optionalA parameter specifying the password used to encrypt the certificate private key.Returns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
var certificate = new X509Certificate2("path/to/certificate.pfx", "password");builder.AddContainer("my-service", "my-image") .WithHttpsCertificate(certificate);This method is not available in polyglot AppHosts. Use Resource instead.
WithHttpsCertificateConfiguration(IResourceBuilder<TResource>, Func<HttpsCertificateConfigurationCallbackAnnotationContext, Task>) Section titled WithHttpsCertificateConfiguration(IResourceBuilder<TResource>, Func<HttpsCertificateConfigurationCallbackAnnotationContext, Task>)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpsCertificateConfiguration<TResource>( this IResourceBuilder<TResource> builder, Func<HttpsCertificateConfigurationCallbackAnnotationContext, Task> callback) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.callbackFunc<HttpsCertificateConfigurationCallbackAnnotationContext, Task> The callback to configure the resource to use a certificate key pair.Returns
IResourceBuilder<TResource> The updated resource builder.Remarks
builder.AddContainer("my-service", "my-image") .WithHttpsCertificateConfiguration(ctx => { ctx.Arguments.Add("--https-certificate-path"); ctx.Arguments.Add(ctx.PfxPath); return Task.CompletedTask; });WithHttpsDeveloperCertificate(IResourceBuilder<TResource>, IResourceBuilder<ParameterResource>) Section titled WithHttpsDeveloperCertificate(IResourceBuilder<TResource>, IResourceBuilder<ParameterResource>)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithHttpsDeveloperCertificate<TResource>( this IResourceBuilder<TResource> builder, IResourceBuilder<ParameterResource>? password = null) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.passwordIResourceBuilder<ParameterResource> optionalA parameter specifying the password used to encrypt the certificate private key.Returns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
builder.AddContainer("my-service", "my-image") .WithHttpsDeveloperCertificate()WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?) Section titled WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool?)extensionIResourceBuilderExtensions.GetEndpoint . The endpoint name will be "https" if not specified. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpsEndpoint<T>( this IResourceBuilder<T> builder, int? port = null, int? targetPort = null, string? name = null, string? env = null, bool? isProxied = null) { // ... }}Parameters
builderIportint?optionalAn optional host port.targetPort int?optionalThis is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?optionalAn optional name of the endpoint. Defaults to "https" if not specified.envstring?optionalAn optional name of the environment variable to inject.isProxied bool?optionalSpecifies if the endpoint will be proxied by DCP. Defaults to null.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
null will not modify the existing endpoint's values. WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool) Section titled WithHttpsEndpoint(IResourceBuilder<T>, int?, int?, string?, string?, bool)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpsEndpoint<T>( this IResourceBuilder<T> builder, int? port, int? targetPort, string? name, string? env, bool isProxied) { // ... }}Parameters
builderIportint?An optional host port.targetPort int?This is the port the resource is listening on. If the endpoint is used for the container, it is the container port.namestring?An optional name of the endpoint. Defaults to "https" if not specified.envstring?An optional name of the environment variable to inject.isProxied boolSpecifies if the endpoint will be proxied by DCP.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
bool isProxied signature. New source that omits isProxied binds to the nullable overload where omission is represented as null. WithHttpsHealthCheck(IResourceBuilder<T>, string?, int?, string?) Section titled WithHttpsHealthCheck(IResourceBuilder<T>, string?, int?, string?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithHttpsHealthCheck<T>( this IResourceBuilder<T> builder, string? path = null, int? statusCode = null, string? endpointName = null) { // ... }}Parameters
builderIpathstring?optionalThe relative path to test.statusCode int?optionalThe result code to interpret as healthy.endpointName string?optionalThe name of the endpoint to derive the base address from.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method adds a health check to the health check service which polls the specified endpoint on the resource on a periodic basis. The base address is dynamically determined based on the endpoint that was selected. By default the path is set to "/" and the status code is set to 200.
This example shows adding an HTTPS health check to a backend project. The health check makes sure that the front end does not start until the backend is reporting a healthy status based on the return code returned from the "/health" path on the backend server.var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend") .WithHttpsHealthCheck("/health");builder.AddProject<Projects.Frontend>("frontend") .WithReference(backend).WaitFor(backend);WithIconName(IResourceBuilder<T>, string, IconVariant) Section titled WithIconName(IResourceBuilder<T>, string, IconVariant)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithIconName<T>( this IResourceBuilder<T> builder, string iconName, IconVariant iconVariant = IconVariant.Filled) { // ... }}Parameters
builderIiconName stringThe name of the FluentUI icon to use. See https://aka.ms/fluentui-system-icons for available icons.iconVariant IconReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method allows you to specify a custom FluentUI icon that will be displayed for the resource in the dashboard. If no custom icon is specified, the dashboard will use default icons based on the resource type.
Set a Redis resource to use the Database icon:var redis = builder.AddContainer("redis", "redis:latest") .WithIconName("Database");var service = builder.AddProject<Projects.MyService>("service") .WithIconName("CloudArrowUp", IconVariant.Regular);WithImagePushOptions(IResourceBuilder<T>, Action<ContainerImagePushOptionsCallbackContext>) Section titled WithImagePushOptions(IResourceBuilder<T>, Action<ContainerImagePushOptionsCallbackContext>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithImagePushOptions<T>( this IResourceBuilder<T> builder, Action<ContainerImagePushOptionsCallbackContext> callback) { // ... }}Parameters
builderIcallbackAction<ContainerImagePushOptionsCallbackContext> The callback to configure push options.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentNullExceptionThrown when builder or callback is null.Remarks
ContainerImagePushOptionsCallbackContext that provides access to the resource and the ContainerImagePushOptions that can be modified. Multiple callbacks can be registered on the same resource, and they will be invoked in the order they were added. Examples
Configure a custom image name and tag for a container resource:
var container = builder.AddContainer("myapp", "myapp:latest") .WithImagePushOptions(context => { context.Options.RemoteImageName = "myorg/myapp"; context.Options.RemoteImageTag = "v1.0.0"; });WithImagePushOptions(IResourceBuilder<T>, Func<ContainerImagePushOptionsCallbackContext, Task>) Section titled WithImagePushOptions(IResourceBuilder<T>, Func<ContainerImagePushOptionsCallbackContext, Task>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithImagePushOptions<T>( this IResourceBuilder<T> builder, Func<ContainerImagePushOptionsCallbackContext, Task> callback) { // ... }}Parameters
builderIcallbackFunc<ContainerImagePushOptionsCallbackContext, Task> The asynchronous callback to configure push options.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentNullExceptionThrown when builder or callback is null.Remarks
ContainerImagePushOptionsCallbackContext that provides access to the resource and the ContainerImagePushOptions that can be modified. Multiple callbacks can be registered on the same resource, and they will be invoked in the order they were added. Examples
Configure image options asynchronously by retrieving values from configuration:
var container = builder.AddContainer("myapp", "myapp:latest") .WithImagePushOptions(async context => { var config = await GetConfigurationAsync(); context.Options.RemoteImageName = config.ImageName; context.Options.RemoteImageTag = config.ImageTag; });WithLaunchToolArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>, string?, bool) Section titled WithLaunchToolArgs(IResourceBuilder<T>, Action<CommandLineArgsCallbackContext>, string?, bool)extensionIrun ./cmd/api for go, -m flask for python, or tool exec <package> --yes -- for dotnet. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithLaunchToolArgs<T>( this IResourceBuilder<T> builder, Action<CommandLineArgsCallbackContext> callback, string? ownedByLaunchConfigurationType = null, bool showInCommandLine = true) { // ... }}Parameters
builderIcallbackAction<CommandLineArgsCallbackContext> Callback that produces the launch tool arguments. It is invoked with an empty CommandLineArgsCallbackContext.Args list; everything it adds becomes the leading arguments. ownedByLaunchConfigurationType string?optional The debug launch configuration type that performs this tool invocation itself, for example "go" or "python" — the same value passed to WithDebugSupport . Leave this null (the default) when the prefix is not a debugging concern and must always be passed to the launched program. showInCommandLine booloptional Whether these arguments are part of the command line shown for the resource in the dashboard. Pass false for a prefix that is pure invocation plumbing the user did not write and cannot act on. Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1 .Remarks
Launch tool arguments are always placed ahead of every argument contributed by With, no matter when this method is called, and no With callback can observe or modify them. Declaring the tool invocation this way therefore avoids any dependency on the order in which resource builder methods are called.
When owned is supplied and the resource is launched by an IDE using a launch configuration of that type (see With), the launch configuration already carries the tool invocation, so these arguments are not passed to the launched program. In every other case — process execution, publish, or when a launch configuration of a different type is active — they are part of the resource's command line.
This has no effect on a container resource, which invokes its program through the image's ENTRYPOINT rather than through a local tool. That matters for executables published as a Dockerfile, because Executable carries the executable's annotations over to the generated container resource.
Calling this method more than once is allowed; the most recent declaration wins. It therefore declares a single tool invocation rather than accumulating one, which is why it is the integration's own description of how it launches the program, not a place for callers to append flags.
WithLaunchToolArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>, string?, bool) Section titled WithLaunchToolArgs(IResourceBuilder<T>, Func<CommandLineArgsCallbackContext, Task>, string?, bool)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithLaunchToolArgs<T>( this IResourceBuilder<T> builder, Func<CommandLineArgsCallbackContext, Task> callback, string? ownedByLaunchConfigurationType = null, bool showInCommandLine = true) { // ... }}Parameters
builderIcallbackFunc<CommandLineArgsCallbackContext, Task> Callback that produces the launch tool arguments. It is invoked with an empty CommandLineArgsCallbackContext.Args list. ownedByLaunchConfigurationType string?optional The debug launch configuration type that performs this tool invocation, or null when the prefix is always passed to the launched program. showInCommandLine booloptionalWhether these arguments appear in the dashboard command line.Returns
IResourceBuilder<T> A reference to the ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentNullException Thrown when builder or callback is null. ArgumentException Thrown when ownedByLaunchConfigurationType is empty. Remarks
WithLifetimeOf(IResourceBuilder<T>, IResourceBuilder<TSource>) Section titled WithLifetimeOf(IResourceBuilder<T>, IResourceBuilder<TSource>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithLifetimeOf<T, TSource>( this IResourceBuilder<T> builder, IResourceBuilder<TSource> sourceBuilder) { // ... }}Parameters
builderIsourceBuilder IResourceBuilder<TSource> The resource builder whose lifetime should be used.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
sourceBuilder when the application model is prepared, so later lifetime changes to the source resource are reflected by this resource. WithManifestPublishingCallback(IResourceBuilder<T>, Action<ManifestPublishingContext>) Section titled WithManifestPublishingCallback(IResourceBuilder<T>, Action<ManifestPublishingContext>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithManifestPublishingCallback<T>( this IResourceBuilder<T> builder, Action<ManifestPublishingContext> callback) { // ... }}Parameters
builderIcallbackAction<ManifestPublishingContext> Callback method which takes a ManifestPublishingContext which can be used to inject JSON into the manifest.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithManifestPublishingCallback(IResourceBuilder<T>, Func<ManifestPublishingContext, Task>) Section titled WithManifestPublishingCallback(IResourceBuilder<T>, Func<ManifestPublishingContext, Task>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithManifestPublishingCallback<T>( this IResourceBuilder<T> builder, Func<ManifestPublishingContext, Task> callback) { // ... }}Parameters
builderIcallbackFunc<ManifestPublishingContext, Task> Callback method which takes a ManifestPublishingContext which can be used to inject JSON into the manifest.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithoutHttpsCertificate(IResourceBuilder<TResource>) Section titled WithoutHttpsCertificate(IResourceBuilder<TResource>)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithoutHttpsCertificate<TResource>( this IResourceBuilder<TResource> builder) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.Returns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
var redis = builder.AddRedis("cache") .WithoutHttpsCertificate();WithParentProcessLifetime(IResourceBuilder<T>, int) Section titled WithParentProcessLifetime(IResourceBuilder<T>, int)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithParentProcessLifetime<T>( this IResourceBuilder<T> builder, int parentProcessId) { // ... }}Parameters
builderIparentProcessId intThe ID of the parent process to monitor.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentOutOfRangeExceptionThrown when parentProcessId is less than or equal to zero.ArgumentExceptionThrown when parentProcessId does not identify a running process.InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.ApiService>("api") .WithParentProcessLifetime(parentProcessId: 1234);
builder.Build().Run();WithParentRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>) Section titled WithParentRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithParentRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> parent) { // ... }}Parameters
builderIparentIResourceBuilder<IResource> The parent of builder.Returns
IResourceBuilder<T> A resource builder.Remarks
The With method is used to add parent relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");
var frontend = builder.AddProject<Projects.Manager>("frontend") .WithParentRelationship(backend);WithParentRelationship(IResourceBuilder<T>, IResource) Section titled WithParentRelationship(IResourceBuilder<T>, IResource)extensionIResourceRelationshipAnnotation to the resource annotations to add a parent-child relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithParentRelationship<T>( this IResourceBuilder<T> builder, IResource parent) { // ... }}Parameters
builderIparentIbuilder.Returns
IResourceBuilder<T> A resource builder.Remarks
The With method is used to add parent relationships to the resource. Relationships are used to link resources together in UI.
var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");
var frontend = builder.AddProject<Projects.Manager>("frontend") .WithParentRelationship(backend.Resource);This method is not available in polyglot AppHosts. Use the IResourceBuilder overload instead.
WithPersistentLifetime(IResourceBuilder<T>) Section titled WithPersistentLifetime(IResourceBuilder<T>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithPersistentLifetime<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.ApiService>("api") .WithPersistentLifetime();
builder.Build().Run();WithProcessCommand(IResourceBuilder<TResource>, string, string, string, IReadOnlyList<string>, ProcessCommandOptions?) Section titled WithProcessCommand(IResourceBuilder<TResource>, string, string, string, IReadOnlyList<string>, ProcessCommandOptions?)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithProcessCommand<TResource>( this IResourceBuilder<TResource> builder, string commandName, string displayName, string executablePath, IReadOnlyList<string>? arguments = null, ProcessCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.commandName stringThe name of command. The name uniquely identifies the command.displayName stringThe display name visible in UI.executablePath stringThe executable path or command name to start.argumentsIReadOnlyList<string> optionalThe command-line arguments for the process.commandOptions ProcessReturns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
The command will be added to the resource represented by builder. When the command executes, the process is started inside the AppHost process. Standard output and standard error are streamed to the command logger and a bounded tail of the combined output is returned as command result data.
This C# overload is not exported to polyglot AppHosts. Use the language-specific static process command API instead.
Examples
var redis = builder.AddRedis("cache") .WithProcessCommand("dotnet-version", "Show .NET version", "dotnet", ["--version"]);WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ProcessCommandSpec>, ProcessCommandOptions?) Section titled WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ProcessCommandSpec>, ProcessCommandOptions?)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithProcessCommand<TResource>( this IResourceBuilder<TResource> builder, string commandName, string displayName, Func<ExecuteCommandContext, ProcessCommandSpec> processSpecFactory, ProcessCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.commandName stringThe name of command. The name uniquely identifies the command.displayName stringThe display name visible in UI.processSpecFactory Func<ExecuteCommandContext, ProcessCommandSpec> A callback that creates the local process specification when the command is invoked.commandOptions ProcessReturns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
The command will be added to the resource represented by builder. When the command executes, process is called inside the AppHost process with the command execution context. Use Execute to read values supplied by the command caller.
Standard output and standard error are streamed to the command logger at Log and a bounded tail of the combined output is returned as command result data. Configure Process to control which exit codes are treated as success. Configure Process to control the number of returned output lines. Configure Process to control whether returned output opens automatically in the dashboard. Configure Process to create a custom command result from the process exit code and output.
This C# callback overload is not available in polyglot AppHosts.
Examples
var redis = builder.AddRedis("cache") .WithProcessCommand( "seed-data", "Seed data", context => new ProcessCommandSpec("dotnet") { Arguments = ["run", "--project", "tools/SeedData", "--", context.Arguments.GetString("dataset") ?? "small"], EnvironmentVariables = { ["ConnectionStrings__db"] = "Host=localhost;Database=db" } }, new ProcessCommandOptions { MaxOutputLineCount = 20 });WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ValueTask<ProcessCommandSpec>>, ProcessCommandOptions?) Section titled WithProcessCommand(IResourceBuilder<TResource>, string, string, Func<ExecuteCommandContext, ValueTask<ProcessCommandSpec>>, ProcessCommandOptions?)extensionIResourceBuilder<TResource> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TResource> WithProcessCommand<TResource>( this IResourceBuilder<TResource> builder, string commandName, string displayName, Func<ExecuteCommandContext, ValueTask<ProcessCommandSpec>> processSpecFactory, ProcessCommandOptions? commandOptions = null) { // ... }}Parameters
builderIResourceBuilder<TResource> The resource builder.commandName stringThe name of command. The name uniquely identifies the command.displayName stringThe display name visible in UI.processSpecFactory Func<ExecuteCommandContext, ValueTask<ProcessCommandSpec>> A callback that creates the local process specification when the command is invoked.commandOptions ProcessReturns
IResourceBuilder<TResource> The ApplicationModel.IResourceBuilder`1 .Remarks
The command will be added to the resource represented by builder. When the command executes, process is called inside the AppHost process with the command execution context. Use Execute to read values supplied by the command caller.
Standard output and standard error are streamed to the command logger at Log and a bounded tail of the combined output is returned as command result data. Configure Process to control which exit codes are treated as success. Configure Process to control the number of returned output lines. Configure Process to control whether returned output opens automatically in the dashboard. Configure Process to create a custom command result from the process exit code and output.
This C# callback overload is not available in polyglot AppHosts.
Examples
var redis = builder.AddRedis("cache") .WithProcessCommand( "seed-data", "Seed data", context => new ValueTask<ProcessCommandSpec>(new ProcessCommandSpec("dotnet") { Arguments = ["run", "--project", "tools/SeedData", "--", context.Arguments.GetString("dataset") ?? "small"], StandardInputContent = "seed" }));WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, string?, bool) Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithConnectionString>, string?, bool)extensionIResourceBuilder<TDestination> IResourceWithConnectionString.ConnectionStringEnvironmentVariable and the logical name is not portable as an environment-variable suffix, Aspire emits both the original name and a portable alias that replaces characters unsupported in environment-variable names. For example, my-db produces ConnectionStrings__my-db and ConnectionStrings__my_db on targets that support both names. Each resource defines the format of the connection string value. The underlying connection string value can be retrieved using I.
Connection strings are also resolved by the configuration system (appSettings.json in the AppHost project, or environment variables). If a connection string is not found on the resource, the configuration system will be queried for a connection string using the resource's name.
public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithConnectionString> source, string? connectionName = null, bool optional = false) { // ... }}Parameters
builderIResourceBuilder<TDestination> The resource where connection string will be injected.sourceIResourceBuilder<IResourceWithConnectionString> The resource from which to extract the connection string.connectionName string?optional An override of the source resource's logical connection name. The physical environment-variable names are derived from this value when it is not null, unless the source resource specifies IResourceWithConnectionString.ConnectionStringEnvironmentVariable , in which case that explicit physical name is preserved. optionalbooloptionaltrue to allow a missing connection string; false to throw an exception if the connection string is not found.Returns
IResourceBuilder<TDestination> The ApplicationModel.IResourceBuilder`1 .Exceptions
DistributedApplicationExceptionThrows an exception if the connection string resolves to null. It can be null if the resource has no connection string, and if the configuration has no connection string for the source resource.WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>) Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>)extensionIResourceBuilder<TDestination> EndpointAnnotation.ExcludeReferenceEndpoint is false) defined on the source resource will be injected using the format defined by the ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{sourceResourceName}__{endpointScheme}__{endpointIndex}={uriString}" for .NET service discovery, or "{RESOURCE_ENDPOINT}={uri}" for endpoint injection. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithServiceDiscovery> source) { // ... }}Parameters
builderIResourceBuilder<TDestination> The resource where the service discovery information will be injected.sourceIResourceBuilder<IResourceWithServiceDiscovery> The resource from which to extract service discovery information.Returns
IResourceBuilder<TDestination> The ApplicationModel.IResourceBuilder`1 .Remarks
All endpoints are included in the default reference set unless explicitly excluded. Resource authors can opt out individual endpoints by setting Endpoint to true (for example, using .With) to exclude them from this method's behavior. Endpoints that have been excluded (such as management or health check endpoints) can still be referenced explicitly using Resource with Resource.
WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>, string) Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<IResourceWithServiceDiscovery>, string)extensionIResourceBuilder<TDestination> EndpointAnnotation.ExcludeReferenceEndpoint is false) defined on the source resource will be injected using the format defined by the ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__{endpointScheme}__{endpointIndex}={uriString}" for .NET service discovery, or "{name}_{ENDPOINT}={uri}" for endpoint injection. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<IResourceWithServiceDiscovery> source, string name) { // ... }}Parameters
builderIResourceBuilder<TDestination> The resource where the service discovery information will be injected.sourceIResourceBuilder<IResourceWithServiceDiscovery> The resource from which to extract service discovery information.namestringThe name of the resource for the environment variable.Returns
IResourceBuilder<TDestination> The ApplicationModel.IResourceBuilder`1 .Remarks
All endpoints are included in the default reference set unless explicitly excluded. Resource authors can opt out individual endpoints by setting Endpoint to true (for example, using .With) to exclude them from this method's behavior. Endpoints that have been excluded (such as management or health check endpoints) can still be referenced explicitly using Resource with Resource.
WithReference(IResourceBuilder<TDestination>, string, Uri) Section titled WithReference(IResourceBuilder<TDestination>, string, Uri)extensionIResourceBuilder<TDestination> ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__default__0={uri}" for .NET service discovery, or "{name}={uri}" for endpoint injection. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, string name, Uri uri) { // ... }}Parameters
builderIResourceBuilder<TDestination> The resource where the service discovery information will be injected.namestringThe name of the service.uriUriThe uri of the service.Returns
IResourceBuilder<TDestination> The ApplicationModel.IResourceBuilder`1 .WithReference(IResourceBuilder<TDestination>, IResourceBuilder<ExternalServiceResource>) Section titled WithReference(IResourceBuilder<TDestination>, IResourceBuilder<ExternalServiceResource>)extensionIResourceBuilder<TDestination> ExternalServiceResource into the destination resource, using the name as the service name. The uri will be injected using the format "services__{name}__default__0={uri}." public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, IResourceBuilder<ExternalServiceResource> externalService) { // ... }}Parameters
builderIResourceBuilder<TDestination> The resource where the service discovery information will be injected.externalService IResourceBuilder<ExternalServiceResource> The external service.Returns
IResourceBuilder<TDestination> The ApplicationModel.IResourceBuilder`1 .WithReference(IResourceBuilder<TDestination>, EndpointReference) Section titled WithReference(IResourceBuilder<TDestination>, EndpointReference)extensionIResourceBuilder<TDestination> ReferenceEnvironmentInjectionAnnotation on the destination resource, i.e. either "services__{name}__{endpointScheme}__{endpointIndex}={uriString}" for .NET service discovery, or "{NAME}_{ENDPOINT}={uri}" for endpoint injection. public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReference<TDestination>( this IResourceBuilder<TDestination> builder, EndpointReference endpointReference) { // ... }}Parameters
builderIResourceBuilder<TDestination> The resource where the service discovery information will be injected.endpointReference EndpointReturns
IResourceBuilder<TDestination> The ApplicationModel.IResourceBuilder`1 .WithReferenceEnvironment(IResourceBuilder<TDestination>, ReferenceEnvironmentInjectionFlags) Section titled WithReferenceEnvironment(IResourceBuilder<TDestination>, ReferenceEnvironmentInjectionFlags)extensionIResourceBuilder<TDestination> public static class ResourceBuilderExtensions{ public static IResourceBuilder<TDestination> WithReferenceEnvironment<TDestination>( this IResourceBuilder<TDestination> builder, ReferenceEnvironmentInjectionFlags flags) { // ... }}Parameters
builderIResourceBuilder<TDestination> The resource to configure.flagsReferenceReturns
IResourceBuilder<TDestination> The ApplicationModel.IResourceBuilder`1 .Remarks
WithReferenceRelationship(IResourceBuilder<T>, IResource) Section titled WithReferenceRelationship(IResourceBuilder<T>, IResource)extensionIResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithReferenceRelationship<T>( this IResourceBuilder<T> builder, IResource resource) { // ... }}Parameters
builderIresourceIReturns
IResourceBuilder<T> A resource builder.Remarks
WithReferenceRelationship(IResourceBuilder<T>, ReferenceExpression) Section titled WithReferenceRelationship(IResourceBuilder<T>, ReferenceExpression)extensionIResourceRelationshipAnnotation s for all resources found in the expression. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithReferenceRelationship<T>( this IResourceBuilder<T> builder, ReferenceExpression expression) { // ... }}Parameters
builderIexpressionReferenceReturns
IResourceBuilder<T> A resource builder.Remarks
WithReferenceRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>) Section titled WithReferenceRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>)extensionIResourceRelationshipAnnotation to the resource annotations to add a reference to another resource. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithReferenceRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> resourceBuilder) { // ... }}Parameters
builderIresourceBuilder IResourceBuilder<IResource> The resource builder that the relationship is to.Returns
IResourceBuilder<T> A resource builder.Remarks
WithRelationship(IResourceBuilder<T>, IResource, string) Section titled WithRelationship(IResourceBuilder<T>, IResource, string)extensionIResourceRelationshipAnnotation to the resource annotations to add a relationship. public static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRelationship<T>( this IResourceBuilder<T> builder, IResource resource, string type) { // ... }}Parameters
builderIresourceItypestringThe relationship type.Returns
IResourceBuilder<T> A resource builder.Remarks
The With method is used to add relationships to the resource. Relationships are used to link resources together in UI. The type indicates information about the relationship type.
var builder = DistributedApplication.CreateBuilder(args);var backend = builder.AddProject<Projects.Backend>("backend");var manager = builder.AddProject<Projects.Manager>("manager") .WithRelationship(backend.Resource, "Manager");This method is not available in polyglot AppHosts.
WithRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>, string) Section titled WithRelationship(IResourceBuilder<T>, IResourceBuilder<IResource>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRelationship<T>( this IResourceBuilder<T> builder, IResourceBuilder<IResource> resourceBuilder, string type) { // ... }}Parameters
builderIresourceBuilder IResourceBuilder<IResource> The resource builder that the relationship is to.typestringThe relationship type.Returns
IResourceBuilder<T> A resource builder.WithRemoteImageName(IResourceBuilder<T>, string) Section titled WithRemoteImageName(IResourceBuilder<T>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRemoteImageName<T>( this IResourceBuilder<T> builder, string remoteImageName) { // ... }}Parameters
builderIremoteImageName stringThe remote image name (e.g., "myapp" or "myorg/myapp").Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentNullExceptionThrown when builder or remoteImageName is null.Remarks
ContainerImagePushOptions.RemoteImageName property. The remote image name should not include the registry endpoint or tag. Those are managed separately. This method can be combined with ResourceBuilderExtensions.WithRemoteImageTag to fully customize the image reference. Examples
Set a custom remote image name for a container:
var container = builder.AddContainer("myapp", "myapp:latest") .WithRemoteImageName("myorg/myapp");WithRemoteImageTag(IResourceBuilder<T>, string) Section titled WithRemoteImageTag(IResourceBuilder<T>, string)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithRemoteImageTag<T>( this IResourceBuilder<T> builder, string remoteImageTag) { // ... }}Parameters
builderIremoteImageTag stringThe remote image tag (e.g., "latest", "v1.0.0").Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
ArgumentNullExceptionThrown when builder or remoteImageTag is null.Remarks
ContainerImagePushOptions.RemoteImageTag property. The tag can be any valid container image tag such as version numbers, environment names, or deployment identifiers. This method can be combined with ResourceBuilderExtensions.WithRemoteImageName to fully customize the image reference. Examples
Set a specific version tag for a container:
var container = builder.AddContainer("myapp", "myapp:latest") .WithRemoteImageTag("v1.0.0");WithSessionLifetime(IResourceBuilder<T>) Section titled WithSessionLifetime(IResourceBuilder<T>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithSessionLifetime<T>( this IResourceBuilder<T> builder) { // ... }}Parameters
builderIReturns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Exceptions
InvalidOperationExceptionThrown when the resource does not support lifetime configuration.Remarks
var builder = DistributedApplication.CreateBuilder(args);
builder.AddProject<Projects.ApiService>("api") .WithSessionLifetime();
builder.Build().Run();WithUrl(IResourceBuilder<T>, string, string?) Section titled WithUrl(IResourceBuilder<T>, string, string?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrl<T>( this IResourceBuilder<T> builder, string url, string? displayText = null) { // ... }}Parameters
builderIurlstringA URL to show for the resource.displayText string?optionalThe display text to show when the link is displayed.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
ResourceBuilderExtensions.WithUrlForEndpoint . Examples
Add a static URL to be displayed for the resource:
var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrl("https://example.com/", "Home");Update all displayed URLs to use the specified path and (optional) display text:
var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrl("/home", "Home");WithUrl(IResourceBuilder<T>, ExpressionInterpolatedStringHandler, string?) Section titled WithUrl(IResourceBuilder<T>, ExpressionInterpolatedStringHandler, string?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrl<T>( this IResourceBuilder<T> builder, in ExpressionInterpolatedStringHandler url, string? displayText = null) { // ... }}Parameters
builderIurlExpressiondisplayText string?optionalThe display text to show when the link is displayed.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
This method is not available in polyglot AppHosts. Use the ReferenceExpression overload instead.
WithUrl(IResourceBuilder<T>, ReferenceExpression, string?) Section titled WithUrl(IResourceBuilder<T>, ReferenceExpression, string?)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrl<T>( this IResourceBuilder<T> builder, ReferenceExpression url, string? displayText = null) { // ... }}Parameters
builderIurlReferenceReferenceExpression that will produce the URL.displayText string?optionalThe display text to show when the link is displayed.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
WithUrlForEndpoint(IResourceBuilder<T>, string, Action<ResourceUrlAnnotation>) Section titled WithUrlForEndpoint(IResourceBuilder<T>, string, Action<ResourceUrlAnnotation>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrlForEndpoint<T>( this IResourceBuilder<T> builder, string endpointName, Action<ResourceUrlAnnotation> callback) { // ... }}Parameters
builderIendpointName stringThe name of the endpoint to customize the URL for.callbackAction<ResourceUrlAnnotation> The callback that will customize the URL.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
Use this method to customize the URL that is automatically added for an endpoint on the resource. To add another URL for an endpoint, use Resource.
The callback will be executed after endpoints have been allocated and the URL has been generated. This allows you to modify the URL or its display text.
If the URL returned by callback is relative, it will be combined with the endpoint URL to create an absolute URL.
If the endpoint with the specified name does not exist, the callback will not be executed and a warning will be logged.
Customize the URL for the "https" endpoint to use the link text "Home":var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrlForEndpoint( "https", url => url.DisplayText = "Home");var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrlForEndpoint("https", url => url.Url = "/home");WithUrlForEndpoint(IResourceBuilder<T>, string, Func<EndpointReference, ResourceUrlAnnotation>) Section titled WithUrlForEndpoint(IResourceBuilder<T>, string, Func<EndpointReference, ResourceUrlAnnotation>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrlForEndpoint<T>( this IResourceBuilder<T> builder, string endpointName, Func<EndpointReference, ResourceUrlAnnotation> callback) { // ... }}Parameters
builderIendpointName stringThe name of the endpoint to add the URL for.callbackFunc<EndpointReference, ResourceUrlAnnotation> The callback that will create the URL.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
Use this method to add another URL for an endpoint on the resource. To customize the URL that is automatically added for an endpoint, use Resource.
The callback will be executed after endpoints have been allocated and the resource is about to start.
If the endpoint with the specified name does not exist, the callback will not be executed and a warning will be logged.
Add a URL for the "https" endpoint that deep-links to an admin page with the text "Admin":var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrlForEndpoint( "https", ep => new() { Url = "/admin", DisplayText = "Admin" });WithUrls(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>) Section titled WithUrls(IResourceBuilder<T>, Action<ResourceUrlsCallbackContext>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrls<T>( this IResourceBuilder<T> builder, Action<ResourceUrlsCallbackContext> callback) { // ... }}Parameters
builderIcallbackAction<ResourceUrlsCallbackContext> The callback that will customize URLs for the resource.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
The callback will be executed after endpoints have been allocated for this resource. This allows you to modify any URLs for the resource, including adding, modifying, or even deletion. Note that any endpoints on the resource will automatically get a corresponding URL added for them.
Update all displayed URLs to have display text:var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrls(c => { foreach (var url in c.Urls) { if (string.IsNullOrEmpty(url.DisplayText)) { url.DisplayText = "frontend"; } } });var frontend = builder.AddProject<Projects.Frontend>("frontend") .WithUrls(c => { foreach (var url in c.Urls) { if (url.Endpoint is not null) { var uri = new UriBuilder( url.Url) { Host = $"{c.Resource.Name}.localhost" }; url.Url = uri.ToString(); } } });WithUrls(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext, Task>) Section titled WithUrls(IResourceBuilder<T>, Func<ResourceUrlsCallbackContext, Task>)extensionIpublic static class ResourceBuilderExtensions{ public static IResourceBuilder<T> WithUrls<T>( this IResourceBuilder<T> builder, Func<ResourceUrlsCallbackContext, Task> callback) { // ... }}Parameters
builderIcallbackFunc<ResourceUrlsCallbackContext, Task> The async callback that will customize URLs for the resource.Returns
IResourceBuilder<T> The ApplicationModel.IResourceBuilder`1 .Remarks
The callback will be executed after endpoints have been allocated for this resource. This allows you to modify any URLs for the resource, including adding, modifying, or even deletion. Note that any endpoints on the resource will automatically get a corresponding URL added for them.