The Aspire AppHost simplifies infrastructure provisioning by generating code to create Azure resources for your applications. This approach lets you model and configure deployment-related aspects directly in your AppHost, reducing the need to rely on tools like Bicep. These aspects include configuring ACA environments, which provide a serverless platform for running containerized applications.
Using the Aspire.Hosting.Azure.AppContainers integration, you can deploy compute resources to Azure Container Apps by adding an ACA environment with AddAzureContainerAppEnvironment. Use PublishAsAzureContainerApp only when you want to customize the generated Container App resource for a project, container, or executable — it does not create the ACA environment. Add an ACA environment first, then use the callback to customize the generated Container App resource.
By using the Azure.Provisioning APIs (explained in Customize Azure resources), you can configure and customize ACA environments along with related resources, such as container registries and file share volumes. Any available deployment setting can be configured. For more information on the available settings, see Microsoft.App managedEnvironments.
The AzureContainerAppEnvironmentResource type models an ACA environment resource. When you call the AddAzureContainerAppEnvironment method, it creates an instance of this type (wrapped in the IResourceBuilder<AzureContainerAppEnvironmentResource>).
A role assignment for the user principal ID to the ACA environment.
Various outputs for the ACA environment.
Using the acaEnv variable, you can chain a call to the ConfigureInfrastructure API to customize the ACA environment to your liking. For more information, see Configure infrastructure.
If you’ve already provisioned an Azure Container Apps environment, chain AsExisting (or asExisting) on AddAzureContainerAppEnvironment to deploy your container apps into it instead of creating a new one:
When the environment is marked as existing, Aspire generates a thin Bicep module that references the existing managed environment by name. It does not emit a new managed environment, Log Analytics workspace, or Aspire Dashboard component — the existing environment already owns those. For background on the AsExisting family of APIs, see Use existing Azure resources.
Some configurations are incompatible with an existing environment and are rejected at publish time:
WithDelegatedSubnet — VNet integration is a property of the managed environment and can’t be reconfigured on an existing one.
WithAzureLogAnalyticsWorkspace — the existing environment already owns its workspace.
Volume mounts on container apps targeting the environment — Azure Files storage attaches to the managed environment, which Aspire can’t change on an existing environment.
By default, even when the environment is existing, Aspire still emits a new user-assigned managed identity and an AcrPull role assignment on the container registry so that newly deployed container apps can pull their images. If your deployment principal can’t create identities or role assignments, or if you have an existing identity that you want to reuse, supply a pre-existing identity with WithAcrPullIdentity (or withAcrPullIdentity):
The environment, container registry, and ACR pull identity can each independently be new or existing. The combination determines whether Aspire emits new resources alongside the references to existing ones:
Environment
Container registry
Pull identity (WithAcrPullIdentity)
What gets emitted beyond references
New
New (default or user-added)
Not supplied
New environment, Log Analytics, Aspire Dashboard, identity, AcrPull role assignment
New
New
Supplied
New environment, Log Analytics, Aspire Dashboard. No identity or role assignment in the env module — wire the role on the identity yourself
New
Existing
Not supplied
New environment, Log Analytics, Aspire Dashboard, identity, AcrPull role assignment on existing registry
New
Existing
Supplied
New environment, Log Analytics, Aspire Dashboard. No identity or role assignment in the env module
Existing
New
Not supplied
New identity, new registry, AcrPull role assignment
Existing
New
Supplied
New registry. No identity or role assignment in the env module
Existing
Existing
Not supplied
New identity, AcrPull role assignment on existing registry
Existing
Existing
Supplied
Nothing — only references to existing resources
The last row is the only configuration in which the env module emits no new identities, role assignments, or supporting resources. Use it when you already have all of the necessary resources provisioned.
The callback receives an AzureResourceInfrastructure instance and the strongly-typed ContainerApp resource. This lets you set any property that Azure Container Apps supports — such as scaling rules, ingress settings, or environment variables — before the Bicep is generated.
By default, AddAzureContainerAppEnvironment uses a different Azure resource naming scheme than the Azure Developer CLI (azd). If you’re upgrading an existing deployment that previously used azd, you might see duplicate Azure resources. To avoid this issue, call the WithAzdResourceNaming method to revert to the naming convention used by azd:
All Azure resources are subclasses of the AzureProvisioningResource type. This enables customization of the generated Bicep by providing a fluent API to configure the Azure resources — using the ConfigureInfrastructure API: