コンテンツにスキップ
ドキュメントAspire を試す
ドキュメント試す

Deploy to Azure App Service

このコンテンツはまだ日本語訳がありません。

🧪 Preview

Use aspire deploy to deploy Aspire applications to Azure App Service. Aspire provisions the App Service plan, Azure Container Registry, managed identity, and the App Service websites for supported web-facing app resources in the App Service environment.

Start with Deploy to Azure for the shared Azure deployment model and target selection.

By default, local deployment uses Azure CLI credentials. Authenticate with Azure CLI before deploying:

Authenticate with Azure CLI
az login

Configure your AppHost for Azure App Service

Section titled “Configure your AppHost for Azure App Service”

Add Azure App Service support to your AppHost:

Aspire CLI — Add Azure App Service
aspire add azure-appservice

The Aspire CLI adds the 📦 Aspire.Hosting.Azure.AppService integration to your AppHost. If prompted, select the matching package result.

Then add the App Service environment in your AppHost and a supported web app or API resource. App Service environments automatically target supported project resources and Dockerfile-backed web containers:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

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

Creates a new distributed application builder

createBuilder
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addAzureAppServiceEnvironment(name: string): AzureAppServiceEnvironmentResource

Adds a azure app service environment resource to the distributed application builder.

addAzureAppServiceEnvironment
("app-service-env");
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addDockerfile(name: string, contextPath: string, options?: {
dockerfilePath?: string;
stage?: string;
}): ContainerResource (+1 overload)

Adds a Dockerfile to the application model that can be treated like a container resource.

addDockerfile
("web", "./web")
.
ContainerResource.withHttpEndpoint(options?: {
port?: number;
targetPort?: number;
name?: string;
env?: string;
isProxied?: boolean;
} | undefined): ContainerResource (+1 overload)

Adds an HTTP endpoint

withHttpEndpoint
({
port?: number | undefined
port
: 8080,
targetPort?: number | undefined
targetPort
: 8080,
name?: string | undefined
name
: "http" })
.
ContainerResource.withExternalHttpEndpoints(): ContainerResource

Marks existing http or https endpoints on a resource as external.

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

Builds the distributed application

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

Runs the distributed application

run
();

For a standard App Service deployment, you only need the environment and a supported app resource. Use PublishAsAzureAppServiceWebsite only when you want to customize the generated website or deployment slot.

How Aspire maps your app to Azure App Service

Section titled “How Aspire maps your app to Azure App Service”

App Service environments automatically target:

  • project resources for web apps and APIs
  • Dockerfile-backed web containers with a supported public HTTP or HTTPS endpoint

Use managed services for backing infrastructure such as databases, caches, and brokers. App Service websites aren’t deployment targets for those workloads.

If one AppHost uses multiple Azure environments, assign each supported resource to the environment you want it to use.

Start with the common case:

AppHost endpoint shapeAzure App Service result
One external HTTP or HTTPS endpointOne public website endpoint

App Service routes public traffic to the app’s target port, even if the app listens on a development port such as 8080.

Azure App Service redirects HTTP traffic to HTTPS at the platform level. To match the deployed serving scheme, Aspire upgrades external HTTP endpoints in an App Service environment to HTTPS on port 443 when it generates endpoint URLs and service discovery connection strings for dependent resources.

This behavior is enabled by default. If you intentionally need generated endpoint URLs and connection strings to preserve http://, disable the upgrade on the App Service environment:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

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

Creates a new distributed application builder

createBuilder
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addAzureAppServiceEnvironment(name: string): AzureAppServiceEnvironmentResource

Adds a azure app service environment resource to the distributed application builder.

addAzureAppServiceEnvironment
("app-service-env")
.
AzureAppServiceEnvironmentResource.withHttpsUpgrade(upgrade?: boolean): AzureAppServiceEnvironmentResource (+1 overload)

Configures whether HTTP endpoints should be automatically upgraded to HTTPS for the Azure App Service environment. By default, HTTP endpoints are upgraded to HTTPS for security and WebSocket compatibility.

withHttpsUpgrade
(false);
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addDockerfile(name: string, contextPath: string, options?: {
dockerfilePath?: string;
stage?: string;
}): ContainerResource (+1 overload)

Adds a Dockerfile to the application model that can be treated like a container resource.

addDockerfile
("web", "./web")
.
ContainerResource.withHttpEndpoint(options?: {
port?: number;
targetPort?: number;
name?: string;
env?: string;
isProxied?: boolean;
} | undefined): ContainerResource (+1 overload)

Adds an HTTP endpoint

withHttpEndpoint
({
port?: number | undefined
port
: 8080,
targetPort?: number | undefined
targetPort
: 8080,
name?: string | undefined
name
: "http" })
.
ContainerResource.withExternalHttpEndpoints(): ContainerResource

Marks existing http or https endpoints on a resource as external.

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

Builds the distributed application

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

Runs the distributed application

run
();

Disabling the upgrade primarily affects generated endpoint configuration for dependent resources. Azure App Service can still redirect HTTP requests to HTTPS after deployment.

Azure App Service uses a public website model:

  • only external http and https endpoints are supported
  • only one distinct external target port is supported for each deployed app
  • internal-only endpoints, multi-port public apps, and arbitrary infrastructure containers such as Redis or databases don’t fit this deployment model

During aspire deploy, Aspire:

  • provisions or attaches an Azure Container Registry
  • builds container images for supported resources
  • pushes those images to the registry
  • creates a user-assigned managed identity
  • grants the deployed websites permission to pull images

This lets App Service pull deployed images without manual registry credentials.

App Service exposes one health check path per website. If you configure multiple probes, Aspire prefers the liveness probe and uses that path for the App Service health check.

Use PublishAsAzureAppServiceWebsite when you want to customize the generated website or deployment slot. It isn’t required for a standard App Service deployment.

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

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

Creates a new distributed application builder

createBuilder
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addAzureAppServiceEnvironment(name: string): AzureAppServiceEnvironmentResource

Adds a azure app service environment resource to the distributed application builder.

addAzureAppServiceEnvironment
("app-service-env");
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: {
launchProfileOrOptions?: ProjectResourceOptions;
}): ProjectResource (+1 overload)

Adds a .NET project resource

addProject
("api", "../Api/Api.csproj")
.
ProjectResource.publishAsAzureAppServiceWebsite(options?: {
configure?: ((arg1: AzureResourceInfrastructure, arg2: WebSite) => Promise<void>) | undefined;
configureSlot?: ((arg1: AzureResourceInfrastructure, arg2: WebSiteSlot) => Promise<void>) | undefined;
} | undefined): ProjectResource (+1 overload)

Publishes the specified compute resource as an Azure App Service or Azure App Service Slot.

publishAsAzureAppServiceWebsite
({
configure?: ((arg1: AzureResourceInfrastructure, arg2: WebSite) => Promise<void>) | undefined
configure
: async (
_infrastructure: AzureResourceInfrastructure
_infrastructure
,
_website: WebSite
_website
) => {
// Customize the generated production website here.
}
});
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

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

Runs the distributed application

run
();

When you use deployment slots, production website customizations and slot customizations are configured separately.

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

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

Creates a new distributed application builder

createBuilder
();
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addAzureAppServiceEnvironment(name: string): AzureAppServiceEnvironmentResource

Adds a azure app service environment resource to the distributed application builder.

addAzureAppServiceEnvironment
("app-service-env")
.
AzureAppServiceEnvironmentResource.withDeploymentSlot(deploymentSlot: string | ParameterResource): AzureAppServiceEnvironmentResource

Configures the deployment slot for all Azure App Services in the environment

withDeploymentSlot
("staging");
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addProject(name: string, projectPath: string, options?: {
launchProfileOrOptions?: ProjectResourceOptions;
}): ProjectResource (+1 overload)

Adds a .NET project resource

addProject
("api", "../Api/Api.csproj")
.
ProjectResource.publishAsAzureAppServiceWebsite(options?: {
configure?: ((arg1: AzureResourceInfrastructure, arg2: WebSite) => Promise<void>) | undefined;
configureSlot?: ((arg1: AzureResourceInfrastructure, arg2: WebSiteSlot) => Promise<void>) | undefined;
} | undefined): ProjectResource (+1 overload)

Publishes the specified compute resource as an Azure App Service or Azure App Service Slot.

publishAsAzureAppServiceWebsite
({
configureSlot?: ((arg1: AzureResourceInfrastructure, arg2: WebSiteSlot) => Promise<void>) | undefined
configureSlot
: async (
_infrastructure: AzureResourceInfrastructure
_infrastructure
,
_slot: WebSiteSlot
_slot
) => {
// Customize the generated deployment slot here.
}
});
await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.build(): DistributedApplication

Builds the distributed application

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

Runs the distributed application

run
();

Azure App Service application settings accept only letters, numbers, and underscores. If a connection name contains dashes and you intentionally want to bypass App Service name validation for that website, call SkipEnvironmentVariableNameChecks() after PublishAsAzureAppServiceWebsite.

apphost.mts
await builder
.addProject("api", "../Api/Api.csproj", "https")
.publishAsAzureAppServiceWebsite()
.skipEnvironmentVariableNameChecks();

For general Azure resource customization such as naming, existing resources, role assignments, and outputs, see Customize Azure resources. For App Service-specific hosting details, see Azure App Service Hosting integration.

Once your AppHost is configured, deploy it with:

Deploy to Azure App Service
aspire deploy

Aspire can prompt for missing Azure settings and AppHost parameters during an interactive deploy, then provisions and deploys the App Service resources behind the scenes.

For Azure authentication, shared Azure settings, and Parameters__* inputs, see Deploy to Azure and Environments.

The Azure App Service environment includes the Aspire Dashboard by default, so you can inspect logs, traces, metrics, and topology for the deployed compute resources after deployment. Managed Azure backing services aren’t shown as dashboard resources there. If you don’t want to deploy it, disable it on the environment:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

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

Creates a new distributed application builder

createBuilder
();
const
const appServiceEnv: AzureAppServiceEnvironmentResource
appServiceEnv
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addAzureAppServiceEnvironment(name: string): AzureAppServiceEnvironmentResource

Adds a azure app service environment resource to the distributed application builder.

addAzureAppServiceEnvironment
("app-service-env");
await
const appServiceEnv: AzureAppServiceEnvironmentResource
appServiceEnv
.
AzureAppServiceEnvironmentResource.withDashboard(enable?: boolean): AzureAppServiceEnvironmentResource (+1 overload)

Configures whether the Aspire dashboard should be included in the Azure App Service environment.

withDashboard
(false);

Enable Azure Application Insights on the App Service environment when you want Aspire to provision monitoring resources and flow the connection string into your deployed websites:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

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

Creates a new distributed application builder

createBuilder
();
const
const appServiceEnv: AzureAppServiceEnvironmentResource
appServiceEnv
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addAzureAppServiceEnvironment(name: string): AzureAppServiceEnvironmentResource

Adds a azure app service environment resource to the distributed application builder.

addAzureAppServiceEnvironment
("app-service-env");
await
const appServiceEnv: AzureAppServiceEnvironmentResource
appServiceEnv
.
AzureAppServiceEnvironmentResource.withAzureApplicationInsights(options?: {
applicationInsights?: AzureApplicationInsightsResource;
}): AzureAppServiceEnvironmentResource (+1 overload)

Enables Azure Application Insights for the Azure App Service environment

withAzureApplicationInsights
();

For existing Application Insights resources and advanced configuration, see Azure App Service Hosting integration.

Use deployment slots when you want to deploy the websites in your environment into a staging slot before swapping into production:

apphost.mts
import {
function createBuilder(): IDistributedApplicationBuilder

Creates a new distributed application builder

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

Creates a new distributed application builder

createBuilder
();
const
const appServiceEnv: AzureAppServiceEnvironmentResource
appServiceEnv
= await
const builder: IDistributedApplicationBuilder
builder
.
IDistributedApplicationBuilder.addAzureAppServiceEnvironment(name: string): AzureAppServiceEnvironmentResource

Adds a azure app service environment resource to the distributed application builder.

addAzureAppServiceEnvironment
("app-service-env");
await
const appServiceEnv: AzureAppServiceEnvironmentResource
appServiceEnv
.
AzureAppServiceEnvironmentResource.withDeploymentSlot(deploymentSlot: string | ParameterResource): AzureAppServiceEnvironmentResource

Configures the deployment slot for all Azure App Services in the environment

withDeploymentSlot
("staging");

For existing plans, advanced customization, and deployment slot behavior, see Azure App Service Hosting integration.

For environment-variable validation details and advanced App Service customization, see Azure App Service Hosting integration.