# AzureContainerAppExtensions Methods

- Package: [Aspire.Hosting.Azure.AppContainers](/reference/api/csharp/aspire.hosting.azure.appcontainers.md)
- Type: [AzureContainerAppExtensions](/reference/api/csharp/aspire.hosting.azure.appcontainers/azurecontainerappextensions.md)
- Kind: `Methods`
- Members: `8`

Provides extension methods for customizing Azure Container App definitions for projects.

## AddAzureContainerAppEnvironment(IDistributedApplicationBuilder, string)

- Name: `AddAzureContainerAppEnvironment(IDistributedApplicationBuilder, string)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureContainerAppEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L104-L439)

Adds a container app environment resource to the distributed application builder.

```csharp
public static class AzureContainerAppExtensions
{
    public static IResourceBuilder<AzureContainerAppEnvironmentResource> AddAzureContainerAppEnvironment(
        this IDistributedApplicationBuilder builder,
        string name)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The distributed application builder.
- `name` (`string`)
  The name of the resource.

## Returns

`IResourceBuilder<AzureContainerAppEnvironmentResource>` -- `ApplicationModel.IResourceBuilder`1`

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## AddAzureContainerAppsInfrastructure(IDistributedApplicationBuilder)

> **Obsolete:** Use AddAzureContainerAppEnvironment instead. This method will be removed in a future version.

- Name: `AddAzureContainerAppsInfrastructure(IDistributedApplicationBuilder)`
- Modifiers: `extension`
- Returns: `IDistributedApplicationBuilder`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L36)

Adds the necessary infrastructure for Azure Container Apps to the distributed application builder.

```csharp
public static class AzureContainerAppExtensions
{
    public static IDistributedApplicationBuilder AddAzureContainerAppsInfrastructure(
        this IDistributedApplicationBuilder builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IDistributedApplicationBuilder`)
  The distributed application builder.

## WithAcrPullIdentity(IResourceBuilder<AzureContainerAppEnvironmentResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)

- Name: `WithAcrPullIdentity(IResourceBuilder<AzureContainerAppEnvironmentResource>, IResourceBuilder<AzureUserAssignedIdentityResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureContainerAppEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L756-L761)

Configures the container app environment to use the supplied `Azure.AzureUserAssignedIdentityResource` as the managed identity that container apps in the environment use to pull images from the configured container registry (the `AcrPull` identity), instead of having Aspire create a new identity and a new `AcrPull` role assignment.

```csharp
public static class AzureContainerAppExtensions
{
    public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithAcrPullIdentity(
        this IResourceBuilder<AzureContainerAppEnvironmentResource> builder,
        IResourceBuilder<AzureUserAssignedIdentityResource> identityBuilder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureContainerAppEnvironmentResource>`)
  The container app environment to configure.
- `identityBuilder` (`IResourceBuilder<AzureUserAssignedIdentityResource>`)
  The resource builder for the user-assigned identity that should be used for image pulls. This identity is only used for the `AcrPull` role; it is not assigned to individual container apps in the environment.

## Returns

`IResourceBuilder<AzureContainerAppEnvironmentResource>` -- The `ApplicationModel.IResourceBuilder`1` for chaining.

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `identityBuilder` is `null`.

## Remarks

When this is set, Aspire will not create a new identity or an `AcrPull` role assignment for the container registry. The caller is responsible for ensuring the supplied identity already has the required `AcrPull` role assignment on the registry, for example by chaining `.WithRoleAssignments(acr, ContainerRegistryBuiltInRole.AcrPull)` when adding the identity.

This is commonly combined with `AsExisting` on the environment and on the container registry to deploy container apps into a pre-provisioned set of Azure resources without Aspire emitting any new identity or role-assignment resources. See [https://github.com/microsoft/aspire/issues/12977](https://github.com/microsoft/aspire/issues/12977) for the scenario this addresses.

Only the combination of an existing environment, an existing container registry, and this method avoids emitting any new identity or role-assignment resources in the env module. Other combinations still work but will emit additional resources:

- If the environment is marked `AsExisting` but no identity is supplied here, Aspire still emits a new `UserAssignedIdentity` and an `AcrPull` role assignment on the configured registry.
- If this method is used but the container registry is not existing (either the Aspire-generated default registry or a user-added registry without `AsExisting`), the registry itself is still provisioned. To wire the supplied identity to that newly-created registry, chain `.WithRoleAssignments(acr, ContainerRegistryBuiltInRole.AcrPull)` on the identity.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithAzdResourceNaming(IResourceBuilder<AzureContainerAppEnvironmentResource>)

- Name: `WithAzdResourceNaming(IResourceBuilder<AzureContainerAppEnvironmentResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureContainerAppEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L617-L618)

Configures the container app environment resources to use the same naming conventions as azd.

```csharp
public static class AzureContainerAppExtensions
{
    public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithAzdResourceNaming(
        this IResourceBuilder<AzureContainerAppEnvironmentResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureContainerAppEnvironmentResource>`)
  The AzureContainerAppEnvironmentResource to configure.

## Returns

`IResourceBuilder<AzureContainerAppEnvironmentResource>` -- `ApplicationModel.IResourceBuilder`1`

## Remarks

By default, the container app environment resources use a different naming convention than azd. This method allows for reusing the previously deployed resources if the application was deployed using azd without calling [AzureContainerAppExtensions.AddAzureContainerAppEnvironment(IDistributedApplicationBuilder, string)](/reference/api/csharp/aspire.hosting.azure.appcontainers/azurecontainerappextensions/methods.md#addazurecontainerappenvironment-idistributedapplicationbuilder-string)

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithAzureLogAnalyticsWorkspace(IResourceBuilder<AzureContainerAppEnvironmentResource>, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>)

- Name: `WithAzureLogAnalyticsWorkspace(IResourceBuilder<AzureContainerAppEnvironmentResource>, IResourceBuilder<AzureLogAnalyticsWorkspaceResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureContainerAppEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L698-L704)

Configures the container app environment resource to use the specified Log Analytics Workspace.

```csharp
public static class AzureContainerAppExtensions
{
    public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithAzureLogAnalyticsWorkspace(
        this IResourceBuilder<AzureContainerAppEnvironmentResource> builder,
        IResourceBuilder<AzureLogAnalyticsWorkspaceResource> workspaceBuilder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureContainerAppEnvironmentResource>`)
  The AzureContainerAppEnvironmentResource to configure.
- `workspaceBuilder` (`IResourceBuilder<AzureLogAnalyticsWorkspaceResource>`)
  The resource builder for the `Azure.AzureLogAnalyticsWorkspaceResource` to use.

## Returns

`IResourceBuilder<AzureContainerAppEnvironmentResource>` -- `ApplicationModel.IResourceBuilder`1`

## Exceptions

- `ArgumentNullException` -- Thrown when `builder` or `workspaceBuilder` is null.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithCompactResourceNaming(IResourceBuilder<AzureContainerAppEnvironmentResource>)

> **Experimental:** ASPIREACANAMING001 - [Learn more](/diagnostics/aspireacanaming001/)

- Name: `WithCompactResourceNaming(IResourceBuilder<AzureContainerAppEnvironmentResource>)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureContainerAppEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L649-L650)

Configures the container app environment to use compact resource naming that maximally preserves the `uniqueString` suffix for length-constrained Azure resources such as storage accounts.

```csharp
public static class AzureContainerAppExtensions
{
    public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithCompactResourceNaming(
        this IResourceBuilder<AzureContainerAppEnvironmentResource> builder)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureContainerAppEnvironmentResource>`)
  The [AzureContainerAppEnvironmentResource](/reference/api/csharp/aspire.hosting.azure.appcontainers/azurecontainerappenvironmentresource.md) to configure.

## Returns

`IResourceBuilder<AzureContainerAppEnvironmentResource>` -- A reference to the `ApplicationModel.IResourceBuilder`1` for chaining.

## Remarks

By default, the generated Azure resource names use long static suffixes (e.g. `storageVolume`, `managedStorage`) that can consume most of the 24-character storage account name limit, truncating the `uniqueString(resourceGroup().id)` portion that provides cross-deployment uniqueness.

When enabled, this method shortens the static portions of generated names so the full 13-character `uniqueString` is preserved. This prevents naming collisions when deploying multiple environments to different resource groups.

This option only affects volume-related storage resources. It does not change the naming of the container app environment, container registry, log analytics workspace, or managed identity. Use [AzureContainerAppExtensions.WithAzdResourceNaming(IResourceBuilder<AzureContainerAppEnvironmentResource>)](/reference/api/csharp/aspire.hosting.azure.appcontainers/azurecontainerappextensions/methods.md#withazdresourcenaming-iresourcebuilder-azurecontainerappenvironmentresource) to change those names as well.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithDashboard(IResourceBuilder<AzureContainerAppEnvironmentResource>, bool)

- Name: `WithDashboard(IResourceBuilder<AzureContainerAppEnvironmentResource>, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureContainerAppEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L663-L664)

Configures whether the Aspire dashboard should be included in the container app environment.

```csharp
public static class AzureContainerAppExtensions
{
    public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithDashboard(
        this IResourceBuilder<AzureContainerAppEnvironmentResource> builder,
        bool enable = true)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureContainerAppEnvironmentResource>`)
  The AzureContainerAppEnvironmentResource to configure.
- `enable` (`bool`) `optional`
  Whether to include the Aspire dashboard. Default is true.

## Returns

`IResourceBuilder<AzureContainerAppEnvironmentResource>` -- `ApplicationModel.IResourceBuilder`1`

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.

## WithHttpsUpgrade(IResourceBuilder<AzureContainerAppEnvironmentResource>, bool)

- Name: `WithHttpsUpgrade(IResourceBuilder<AzureContainerAppEnvironmentResource>, bool)`
- Modifiers: `extension`
- Returns: `IResourceBuilder<AzureContainerAppEnvironmentResource>`
- Source: [GitHub](https://github.com/microsoft/aspire/blob/cbc352350f1a9bafbaff10d14a2c8de4ac186a48/src/Aspire.Hosting.Azure.AppContainers/AzureContainerAppExtensions.cs#L683-L684)

Configures whether HTTP endpoints should be upgraded to HTTPS in Azure Container Apps. By default, HTTP endpoints are upgraded to HTTPS for security and WebSocket compatibility.

```csharp
public static class AzureContainerAppExtensions
{
    public static IResourceBuilder<AzureContainerAppEnvironmentResource> WithHttpsUpgrade(
        this IResourceBuilder<AzureContainerAppEnvironmentResource> builder,
        bool upgrade = true)
    {
        // ...
    }
}
```

## Parameters

- `builder` (`IResourceBuilder<AzureContainerAppEnvironmentResource>`)
  The AzureContainerAppEnvironmentResource to configure.
- `upgrade` (`bool`) `optional`
  Whether to upgrade HTTP endpoints to HTTPS. Default is true.

## Returns

`IResourceBuilder<AzureContainerAppEnvironmentResource>` -- `ApplicationModel.IResourceBuilder`1`

## Remarks

When disabled ( `false`), HTTP endpoints will use HTTP scheme and port 80 in Azure Container Apps. Note that explicit ports specified for development (e.g., port 8080) are still normalized to standard ports (80/443) as required by Azure Container Apps.

## ATS metadata

### ATS export

- Available to Polyglot AppHosts through the Aspire Type System.
