Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Azure Developer CLI (azd) enables you to deploy Aspire projects using GitHub Actions or Azure Devops pipelines by automatically configuring the required authentication and environment settings. This article walks you through the process of creating and deploying an Aspire project on Azure Container Apps using azd. You learn the following concepts:
- Explore how
azdintegration works with Aspire projects - Create and configure a GitHub or Azure DevOps repository for an Aspire project using
azd - Monitor and explore GitHub Actions workflow or Azure DevOps pipeline executions and Azure deployments
Prerequisites
To work with Aspire, you need the following installed locally:
- .NET 8.0 or .NET 9.0.
- Starting with Aspire 9.4, .NET 10 Preview 5 or later is supported.
- An OCI compliant container runtime, such as:
- Docker Desktop or Podman. For more information, see Container runtime.
- An Integrated Developer Environment (IDE) or code editor, such as:
- Visual Studio 2022 version 17.9 or higher (Optional)
- Visual Studio Code (Optional)
- C# Dev Kit: Extension (Optional)
- JetBrains Rider with Aspire plugin (Optional)
For more information, see Aspire setup and tooling, and Aspire SDK.
- Create an Azure DevOps organization or choose an existing organization
- Create an Azure DevOps Personal Access Token (PAT) and save it for later use. Configure the token with the following permissions:
- Agent Pools (read, manage)
- Build (read and execute)
- Code (full)
- Project and team (read, write and manage)
- Release (read, write, execute and manage)
- Service Connections (read, query and manage)
You also need to have the Azure Developer CLI installed locally (version 1.5.1 or higher). Common install options include the following:
Create an Aspire solution
As a starting point, this article assumes that you've created an Aspire solution from the Aspire Starter Application template. For more information, see Quickstart: Build your first Aspire app.
Initialize the template
Open a new terminal window and
cdinto the directory of your Aspire solution.Execute the
azd initcommand to initialize your project withazd, which will inspect the local directory structure and determine the type of app.azd initFor more information on the
azd initcommand, see azd init.Select Use code in the current directory when
azdprompts you with three app initialization options.? How do you want to initialize your app? [Use arrows to move, type to filter] > Use code in the current directory Select a template Create a minimal projectAfter scanning the directory,
azdprompts you to confirm that it found the correct Aspire AppHost project. Select the Confirm and continue initializing my app option.Detected services: .NET (Aspire) Detected in: D:\source\repos\AspireSample\AspireSample.AppHost\AspireSample.AppHost.csproj azd will generate the files necessary to host your app on Azure using Azure Container Apps. ? Select an option [Use arrows to move, type to filter] > Confirm and continue initializing my app Cancel and exitEnter an environment name, which is used to name provisioned resources in Azure and managing different environments such as
devandprod.Generating files to run your app on Azure: (✓) Done: Generating ./azure.yaml (✓) Done: Generating ./next-steps.md SUCCESS: Your app is ready for the cloud! You can provision and deploy your app to Azure by running the azd up command in this directory. For more information on configuring your app, see ./next-steps.md
azd generates a number of files and places them into the working directory. These files are:
- azure.yaml: Describes the services of the app, such as Aspire AppHost project, and maps them to Azure resources.
- .azure/config.json: Configuration file that informs
azdwhat the current active environment is. - .azure/aspireazddev/.env: Contains environment specific overrides.
Create the GitHub repository and pipeline
The Azure Developer CLI enables you to automatically create CI/CD pipelines with the correct configurations and permissions to provision and deploy resources to Azure. azd can also create a GitHub repository for your app if it doesn't exist already.
Run the
azd pipeline configcommand to configure your deployment pipeline and securely connect it to Azure:azd pipeline configSelect the subscription to provision and deploy the app resources to.
Select the Azure location to use for the resources.
When prompted whether to create a new Git repository in the directory, enter y and press Enter.
Note
Creating a GitHub repository required you being logged into GitHub. There are a few selections that vary based on your preferences. After logging in, you will be prompted to create a new repository in the current directory.
Select Create a new private GitHub repository to configure the git remote.
Enter a name of your choice for the new GitHub repository or press enter to use the default name.
azdcreates a new repository in GitHub and configures it with the necessary secrets required to authenticate to Azure.
Enter y to proceed when
azdprompts you to commit and push your local changes to start the configured pipeline.
Explore the GitHub Actions workflow and deployment
Navigate to your new GitHub repository using the link output by
azd.Select the Actions tab to view the repository workflows. You should see the new workflow either running or already completed. Select the workflow to view the job steps and details in the logs of the run. For example, you can expand steps such as Deploy application to see the details of the completed action.
Select Deploy Application to expand the logs for that step. You should see two endpoint urls printed out for the
apiserviceandwebfrontend. Select either of these links to open them in another browser tab and explore the deployed application.
Congratulations! You successfully deployed an Aspire project using the Azure Developer CLI and GitHub Actions.
Configure working directory for multi-project solutions
When you add GitHub Actions to an existing multi-project Aspire solution where the AppHost project isn't in the root directory, you might need to configure the working-directory parameter for certain workflow steps. This section explains when and how to make these adjustments.
When working-directory configuration is needed
The azd pipeline config command generates a GitHub Actions workflow that assumes your Aspire AppHost project is in the root directory of your repository. However, in many real-world scenarios, especially when adding Aspire to existing applications, the AppHost project might be in a subdirectory.
For example, if your repository structure looks like this:
└───📂 MyAspireApp
├───📂 MyAspireApp.ApiService
├───📂 MyAspireApp.AppHost
│ ├─── MyAspireApp.AppHost.csproj
│ └─── AppHost.cs
├───📂 MyAspireApp.Web
└─── MyAspireApp.sln
The generated workflow steps for Provision Infrastructure and Deploy Application need to run from the MyAspireApp.AppHost directory, not from the repository root.
Updating the GitHub Actions workflow
After running azd pipeline config, examine the generated workflow file in .github/workflows/azure-dev.yml. Look for steps that run azd commands and add the working-directory parameter as needed.
Here's an example of the original generated steps:
- name: Provision Infrastructure
run: azd provision --no-prompt
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Deploy Application
run: azd deploy --no-prompt
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
Update these steps to include the working-directory parameter:
- name: Provision Infrastructure
run: azd provision --no-prompt
working-directory: ./MyAspireApp.AppHost
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
- name: Deploy Application
run: azd deploy --no-prompt
working-directory: ./MyAspireApp.AppHost
env:
AZURE_ENV_NAME: ${{ vars.AZURE_ENV_NAME }}
AZURE_LOCATION: ${{ vars.AZURE_LOCATION }}
AZURE_SUBSCRIPTION_ID: ${{ vars.AZURE_SUBSCRIPTION_ID }}
Finding the correct working directory
The working directory should point to the folder containing your Aspire AppHost project (the project that contains the azure.yaml file generated by azd init). You can identify this directory by:
- Look for the project with the
Aspire.AppHostpackage reference in its.csprojfile. - Find the directory containing the azure.yaml file.
- Locate the project referenced in your solution that orchestrates other services.
Note
Some azd commands, such as azd init during pipeline setup, might also need the working-directory parameter if they're not running from the AppHost project directory.
Create the Azure DevOps repository and pipeline
Important
As mentioned in the prerequisites, you'll need to create an Azure DevOps organization or select an existing organization to complete the steps ahead. You will also need to create a Personal Access Token (PAT) with the permissions listed in the prerequisites.
The Azure Developer CLI enables you to automatically create pipelines with the correct configurations and permissions to provision and deploy resources to Azure. azd can also create an Azure Pipelines repository for your app if it doesn't exist already.
Run the
azd pipeline configcommand to configure your deployment pipeline and securely connect it to Azure. Include the--provider azdooption to use Azure Pipelines instead of the default GitHub Actions configuration.azd pipeline config --provider azdoImportant
Before running
azd pipeline config, ensure you have successfully runazd initto initialize your project. If you encounter errors like "no project exists" during pipeline execution, see the troubleshooting section for solutions.Select the subscription to provision and deploy the app resources to.
Select the Azure location to use for the resources.
Paste the Personal Access Token you created earlier.
Enter the Azure DevOps Organization name you created or selected.
When prompted to create a new repository in the current directory, enter y and press Enter.
When prompted to configure the git remote, select Create a new Azure DevOps Project.
Enter a unique name of your choice for the new repository, such as
aspireazd.azdcreates a new repository in Azure Repos and configures it with the necessary secrets required to authenticate to Azure.Enter y to proceed when
azdprompts you to commit and push your local changes to start the configured pipeline.
Explore the pipeline and deployed app
Navigate to your new Azure Pipeline using the status link output by
azd.Select the completed pipeline run to view the summary.
Select the job link at the bottom of the view to navigate to the job details.
The job details page shows the status of all the individual stages. Select Provision Infrastructure to view the logs for that stage, which detail all of the provisioning steps completed by
azd. At the bottom of the logs take note of the final status message and link to the provisioned Azure resource group.Select the link at the bottom of the provisioning output logs to navigate to the new Azure resource group.
Note
You can also navigate directly to your new resource group by searching for it in the Azure Portal. Your resource group name will be the environment name you provided to
azdprefixed withrg-.Select the webfrontend container app, which hosts the public facing portion of your site.
On the webfrontend details page, select the Application Url link to open your site in the browser.
Important
If you encounter a 403 Forbidden error when viewing your site in the browser, make sure the ingress settings are configured correctly. On the webfrontend app page in the Azure Portal, navigate to Ingress on the left navigation. Make sure Ingress traffic is set to Accepting traffic from anywhere and save your changes.
Congratulations! You successfully deployed an Aspire project using the Azure Developer CLI and Azure Pipelines.
Troubleshoot Azure DevOps pipeline deployment
This section covers common issues you might encounter when deploying Aspire projects using Azure DevOps pipelines.
ERROR: no project exists; to create a new project, run azd init
Problem: During the provisioning step of your Azure DevOps pipeline, you encounter the error message:
ERROR: no project exists; to create a new project, run azd init
Cause: This error occurs because the azd init command generates files (azure.yaml and the .azure folder) that are typically not committed to your repository. When the pipeline runs in a clean environment, these files don't exist, causing azd commands to fail.
Solution: There are several approaches to resolve this issue:
Option 1: Run azd init in your pipeline (Recommended)
Add an azd init step to your Azure DevOps pipeline before the provisioning step. You can use the --from-code and --no-prompt flags to run the command non-interactively:
- task: AzureCLI@2
displayName: 'Initialize Azure Developer CLI'
inputs:
azureSubscription: '$(AZURE_SERVICE_CONNECTION)'
scriptType: 'bash'
scriptLocation: 'inlineScript'
inlineScript: |
azd init --from-code --no-prompt
azd env new $(AZURE_ENV_NAME) --location $(AZURE_LOCATION) --subscription $(AZURE_SUBSCRIPTION_ID)
Note
If you encounter prompts even with --no-prompt, try running azd init and azd env new as separate steps, or use environment variables to provide answers to any prompts. The --from-code flag tells azd to use the existing code in the current directory rather than creating a new project from a template.
Make sure to define the following variables in your pipeline:
AZURE_ENV_NAME: Your environment name (for example,devorprod).AZURE_LOCATION: Your Azure region (for example,eastus2).AZURE_SUBSCRIPTION_ID: Your Azure subscription ID.
Option 2: Commit required files to your repository
If you prefer to commit the generated files to your repository:
- Run
azd initlocally in your project directory. - Add the generated
azure.yamlfile to your repository. - Optionally, add the
.azurefolder to your repository if you want to preserve environment-specific settings.
Note
The .azure folder contains environment-specific configuration that might include sensitive information. Review the contents carefully before committing to your repository.
Option 3: Use azd pipeline config with proper initialization
Ensure that you run azd pipeline config --provider azdo after successfully running azd init locally. This command should set up the pipeline with the correct configuration that handles the initialization automatically.
If you continue to experience issues, verify that:
- Your project structure matches what
azdexpects for Aspire projects. - You're running the commands from the correct directory (typically where your
.slnfile is located). - Your Azure DevOps service connection has the necessary permissions for provisioning resources.
Clean up resources
Run the following Azure CLI command to delete the resource group when you no longer need the Azure resources you created. Deleting the resource group also deletes the resources contained inside of it.
az group delete --name <your-resource-group-name>
For more information, see Clean up resources in Azure.