Pular para o conteúdo
Docs Try Aspire
Docs Try

Deploy to Azure App Service

Este conteúdo não está disponível em sua língua ainda.

🧪 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.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureAppServiceEnvironment("app-service-env");
builder.AddDockerfile("web", "./web")
.WithHttpEndpoint(port: 8080, targetPort: 8080, name: "http")
.WithExternalHttpEndpoints();
builder.Build().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 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.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureAppServiceEnvironment("app-service-env");
builder.AddProject<Projects.Api>("api")
.PublishAsAzureAppServiceWebsite((infrastructure, website) =>
{
website.AppSettings.Add("ASPNETCORE_ENVIRONMENT", new AppServiceConfigurationSetting
{
Name = "ASPNETCORE_ENVIRONMENT",
Value = "Production"
});
website.Tags.Add("Environment", "Production");
});
builder.Build().Run();

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

AppHost.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureAppServiceEnvironment("app-service-env")
.WithDeploymentSlot("staging");
builder.AddProject<Projects.Api>("api")
.PublishAsAzureAppServiceWebsite(
configure: (infrastructure, website) =>
{
website.Tags.Add("Environment", "Production");
},
configureSlot: (infrastructure, slot) =>
{
slot.Tags.Add("Environment", "Staging");
});
builder.Build().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.cs
builder.AddProject<Projects.Api>("api")
.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.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureAppServiceEnvironment("app-service-env")
.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.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureAppServiceEnvironment("app-service-env")
.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.cs
var builder = DistributedApplication.CreateBuilder(args);
builder.AddAzureAppServiceEnvironment("app-service-env")
.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.