Este conteúdo não está disponível em sua língua ainda.
🧪 Preview
This article is the reference for the Aspire Azure App Service Hosting integration. It enumerates the AppHost APIs — with examples for both AppHost.cs and apphost.mts — that you use to model an Azure App Service environment in your AppHost project.
To deploy compute resources to Azure App Service, first add an App Service environment to your AppHost. The environment represents the hosting infrastructure (App Service Plan) into which Aspire deploys your project and container resources.
var builder =DistributedApplication.CreateBuilder(args);
var appServiceEnv =builder.AddAzureAppServiceEnvironment("app-service-env");
builder.AddProject<Projects.WebApi>("api");
// After adding all resources, run the app...
builder.Build().Run();
When you call addAzureAppServiceEnvironment (or AddAzureAppServiceEnvironment in C#), Aspire implicitly enables Azure provisioning for the application.
All project resources and Dockerfile-backed containers in the AppHost are automatically targeted to the App Service environment when it’s present — no explicit wiring is required.
During local development the projects run locally as usual. When you publish, each eligible resource is deployed as an Azure App Service website within the provisioned environment.
When the App Service environment is provisioned in Azure, the following resources are created:
App Service Plan — A Premium P0V3 Linux-based hosting plan.
Azure Container Registry — A Basic SKU registry for storing container images.
User-assigned Managed Identity — For secure access between App Service and the Container Registry.
Role Assignments — ACR Pull role assigned to the managed identity.
By default, Aspire generates an App Service website for each eligible resource without additional configuration. Use PublishAsAzureAppServiceWebsite (C#) or publishAsAzureAppServiceWebsite (TypeScript) when you need to customize the generated website — for example to add application settings or tags:
Deployment slots let you deploy your app to a staging environment for testing before swapping it into production. The WithDeploymentSlot extension method (or withDeploymentSlot in TypeScript) configures a deployment slot for the App Service environment:
When you deploy to a slot, the deployment behavior depends on whether the production App Service already exists:
New App Service: If the production App Service doesn’t exist at the time of deployment, Aspire deploys to both the production App Service and the specified deployment slot.
Existing App Service: If the production App Service already exists, Aspire deploys only to the specified deployment slot.
When you customize App Service resources using PublishAsAzureAppServiceWebsite (or publishAsAzureAppServiceWebsite) or ConfigureInfrastructure, those customizations apply to the production slot by default. Apply them separately to each slot when needed using the configureSlot option:
#pragmawarningdisable ASPIREAZURE003 // Azure Virtual Network APIs are experimental.
var builder =DistributedApplication.CreateBuilder(args);
var vnet =builder.AddAzureVirtualNetwork("vnet");
var subnet =vnet.AddSubnet("app-service-subnet","10.0.0.0/24");
var appServiceEnv =builder.AddAzureAppServiceEnvironment("app-service-env")
.WithDelegatedSubnet(subnet);
#pragmawarningrestore ASPIREAZURE003
builder.AddProject<Projects.WebApi>("api");
builder.Build().Run();
WithDelegatedSubnet delegates the subnet to Microsoft.Web/serverFarms and configures every generated website, deployment slot, and the default Aspire Dashboard to use it for regional virtual network integration. The subnet must meet the Azure App Service regional virtual network integration requirements.
For more information on configuring virtual networks and subnets, see Azure Virtual Network.
All Aspire Azure resources expose a ConfigureInfrastructure API (or configureInfrastructure in TypeScript) that lets you customize the generated Bicep through the Azure.Provisioning APIs. For example, you can change the App Service Plan SKU:
If you’re new to Bicep, it’s a domain-specific language for defining Azure resources. With Aspire, you don’t need to write Bicep by hand — the provisioning APIs generate it for you. When you publish your app, the generated Bicep is output alongside the manifest file.
When you add an Azure App Service environment, the following key resources are provisioned:
App Service Plan — A Premium P0V3 Linux-based hosting plan.
Azure Container Registry — A Basic SKU registry for storing container images.
User-assigned Managed Identity — For secure access between App Service and Container Registry.
Role Assignments — ACR Pull role assigned to the managed identity.
The generated Bicep is a starting point and is influenced by changes to the provisioning infrastructure in your AppHost. Customize the Bicep through the C# or TypeScript provisioning APIs — direct edits to generated Bicep files are overwritten on the next publish.