This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Note
Access to this page requires authorization. You can trysigning in orchanging directories.
Access to this page requires authorization. You can trychanging directories.
In this quickstart, you will learn how to create a GitHub workflow to publish your .NET app from source code. Automatically publishing your .NET app from GitHub to a destination is referred to as a continuous deployment (CD). There are many possible destinations to publish an application, in this quickstart you'll publish to Azure.
To publish the app to Azure, open the Azure portal for the App Service instance of the application. In the resourceOverview, selectGet publish profile and save the *.PublishSetting file locally.

Warning
The publish profile contains sensitive information, such as credentials for accessing your Azure App Service resource. This information should always be treated very carefully.
In the GitHub repository, navigate toSettings and selectSecrets from the left navigation menu. SelectNew repository secret, to add a new secret.

EnterAZURE_PUBLISH_PROFILE as theName, and paste the XML content from the publish profile into theValue text area. SelectAdd secret. For more information, seeEncrypted secrets.
In the GitHub repository, add a new YAML file to the.github/workflows directory. Choose a meaningful file name, something that will clearly indicate what the workflow is intended to do. For more information, seeWorkflow file.
Important
GitHub requires that workflow composition files to be placed within the.github/workflows directory.
Workflow files typically define a composition of one or more GitHub Action via thejobs.<job_id>/steps[*]. For more information, see,Workflow syntax for GitHub Actions.
Create a new file namedpublish-app.yml, copy and paste the following YML contents into it:
name: publishon: push: branches: [ production ]env: AZURE_WEBAPP_NAME: DotNetWeb AZURE_WEBAPP_PACKAGE_PATH: '.' # Set this to the path to your web app project, defaults to the repository root: DOTNET_VERSION: '6.0.401' # The .NET SDK version to usejobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup .NET Core uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Install dependencies run: dotnet restore - name: Build run: | cd DotNet.WebApp dotnet build --configuration Release --no-restore dotnet publish -c Release -o ../dotnet-webapp -r linux-x64 --self-contained true /p:UseAppHost=true - name: Test run: | cd DotNet.WebApp.Tests dotnet test --no-restore --verbosity normal - uses: azure/webapps-deploy@v2 name: Deploy with: app-name: ${{ env.AZURE_WEBAPP_NAME }} publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }} package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/dotnet-webapp'In the preceding workflow composition:
Thename: publish defines the name, "publish" will appear in workflow status badges.
name: publishTheon node signifies the events that trigger the workflow:
on: push: branches: [ production ]push occurs on theproduction branch.Theenv node defines named environment variables (env var).
env: AZURE_WEBAPP_NAME: DotNetWeb AZURE_WEBAPP_PACKAGE_PATH: '.' # Set this to the path to your web app project, defaults to the repository root: DOTNET_VERSION: '6.0.401' # The .NET SDK version to useAZURE_WEBAPP_NAME is assigned the valueDotNetWeb.AZURE_WEBAPP_PACKAGE_PATH is assigned the value'.'.DOTNET_VERSION is assigned the value'6.0.401'. The environment variable is later referenced to specify thedotnet-version of theactions/setup-dotnet@v3 GitHub Action.Thejobs node builds out the steps for the workflow to take.
jobs: publish: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - name: Setup .NET Core uses: actions/setup-dotnet@v3 with: dotnet-version: ${{ env.DOTNET_VERSION }} - name: Install dependencies run: dotnet restore - name: Build run: | cd DotNet.WebApp dotnet build --configuration Release --no-restore dotnet publish -c Release -o ../dotnet-webapp -r linux-x64 --self-contained true /p:UseAppHost=true - name: Test run: | cd DotNet.WebApp.Tests dotnet test --no-restore --verbosity normal - uses: azure/webapps-deploy@v2 name: Deploy with: app-name: ${{ env.AZURE_WEBAPP_NAME }} publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }} package: '${{ env.AZURE_WEBAPP_PACKAGE_PATH }}/dotnet-webapp'publish that will run on the latest version of Ubuntu.actions/setup-dotnet@v3 GitHub Action is used to set up the .NET SDK with the specified version from theDOTNET_VERSION environment variable.dotnet restore command is called.dotnet build command is called.dotnet publish command is called.dotnet test command is called.azure/webapps-deploy@v2 GitHub Action deploys the app with the givenpublish-profile andpackage.publish-profile is assigned from theAZURE_PUBLISH_PROFILE repository secret.It's common nomenclature for GitHub repositories to have aREADME.md file at the root of the repository directory. Likewise, it's nice to report the latest status for various workflows. All workflows can generate a status badge, which are visually appealing within theREADME.md file. To add the workflow status badge:
From the GitHub repository select theActions navigation option.
All repository workflows are displayed on the left-side, select the desired workflow and the ellipsis (...) button.
Select theCreate status badge menu option.
Select theCopy status badge Markdown button.
Paste the Markdown into theREADME.md file, save the file, commit and push the changes.
For more, seeAdding a workflow status badge.
| Passing | Failing | No status |
|---|---|---|
Was this page helpful?
Need help with this topic?
Want to try using Ask Learn to clarify or guide you through this topic?
Was this page helpful?
Want to try using Ask Learn to clarify or guide you through this topic?