Deploying .NET Aspire to Azure
Deploy your .NET Aspire application to Azure Container Apps in minutes using the Azure Developer CLI (azd). This guide covers the commands you need and the concepts interviewers ask about.
Prerequisites
Section titled “Prerequisites”Required tools:
- .NET 9.0 SDK (
dotnet --version) - Azure Developer CLI (
brew tap azure/azd && brew install azd) - Docker Desktop (must be running)
- Azure CLI (optional:
brew install azure-cli)
Azure account:
- Subscription with Owner or Contributor role
- User Access Administrator role (for managed identity assignments)
Initial Setup
Section titled “Initial Setup”Authenticate and verify
Section titled “Authenticate and verify”# Login to Azureazd auth login
# Verify authenticationazd auth show
# Verify your project has azure.yaml (Aspire generates this)cat azure.yamlYour azure.yaml should reference your AppHost project — azd reads it to generate infrastructure templates.
Core azd Workflow
Section titled “Core azd Workflow”Full deployment (most common)
Section titled “Full deployment (most common)”# Create development environment (first time only)azd env new dev
# Full deployment: package → provision → deployazd upThat’s it. azd packages your containers, provisions all Azure resources, and deploys them.
Step-by-step workflow (when needed)
Section titled “Step-by-step workflow (when needed)”# Package app into containersazd package
# Provision infrastructure onlyazd provision
# Deploy app onlyazd deploy
# Deploy specific serviceazd deploy appEnvironment Management
Section titled “Environment Management”# Create environmentazd env new <name>
# List environmentsazd env list
# Switch environmentazd env select <name>
# Set environment variableazd env set KEY value
# View all variablesazd env get-valuesKeep separate environments for dev/prod — switch between them with azd env select.
Dev vs Prod Deployment
Section titled “Dev vs Prod Deployment”| Step | Development | Production |
|---|---|---|
| Create env | azd env new dev | azd env new prod |
| Set vars | Minimal — just ASPNETCORE_ENVIRONMENT=Development | Full: add JWT keys, database connections, etc. |
| Deploy | azd up (infra will be rebuilt) | azd up (same command, but infra is production-grade) |
| Secrets | Can use env vars | Must use Key Vault references |
| Teardown | azd down (safe to delete daily) | Never run azd down without backup |
CI/CD with azd pipeline config
Section titled “CI/CD with azd pipeline config”# Set up GitHub Actions or Azure DevOpsazd pipeline config
# Select your platform when prompted# azd generates the workflow file automaticallyMonitoring & Logs
Section titled “Monitoring & Logs”# View deployment infoazd show
# Open monitoring dashboardazd monitor
# Stream application logsazd monitor --logs
# Get detailed environment infoazd env get-valuesUse azd monitor to open Application Insights — critical for production debugging.
Security Best Practices
Section titled “Security Best Practices”Use Key Vault for secrets
Section titled “Use Key Vault for secrets”# Store secrets in Azure Key Vault (never in env vars for production)azd env set KEYVAULT_NAME your-vault-nameConfigure your app to read from Key Vault using managed identity:
var keyVaultUrl = new Uri($"https://{keyVaultName}.vault.azure.net/");config.AddAzureKeyVault(keyVaultUrl, new DefaultAzureCredential());Managed identity (automatic)
Section titled “Managed identity (automatic)”# azd enables managed identity by default# Your Container App gets an identity automatically# Grant it Key Vault access in Azure Portal# → Access Management → Add role assignment (Key Vault Secrets User)Network & encryption
Section titled “Network & encryption”- Container Apps use SSL/TLS by default for data in transit
- Cosmos DB encryption at rest is enabled automatically
- Restrict Container Apps ingress: use internal ingress for internal services
Resource Commands Reference
Section titled “Resource Commands Reference”# Environment managementazd env new <name> # Create environmentazd env select <name> # Switch environmentazd env set KEY value # Set variable
# Deploymentazd up # Full deploymentazd provision # Infrastructure onlyazd deploy # Application only
# Monitoringazd show # Show deployment infoazd monitor # Open Application Insights
# Infrastructureazd infra gen # Generate Bicep files (review before prod)azd down # Delete all resources
# CI/CDazd pipeline config # Set up GitHub Actions / Azure DevOpsQuick Start Checklist
Section titled “Quick Start Checklist”- Run
azd auth login - Run
azd env new dev - Run
azd up(first deploy takes ~15 min) - Test your app in Azure Portal or via the output endpoint
- For production:
azd env new prod→ set secrets in Key Vault →azd up - Set up CI/CD:
azd pipeline config - Monitor logs:
azd monitor --logs
Need help? Check Application Insights logs via azd monitor. For deployment failures, run azd env get-values to verify all variables are set. Still stuck? The azd team maintains excellent docs.