How to Deploy a .NET Web App to Azure with GitHub Actions

February 17, 2023#Software Development
Author image.

Philippe Vaillancourt, Senior Consultant

In today’s digital age, having a website or a web application has become a necessity for businesses and individuals alike. But deploying a web application can be a daunting task for someone who doesn’t have experience with DevOps or cloud services.

In the video above, I explore how to set up automatic deployment of a web application to Azure using GitHub Actions. The following is a brief overview.

The first step is to create an Azure App Service. You can do this by going to the Azure Portal, selecting App Services, and then clicking on Add. Fill in the necessary details, such as the name, subscription, and resource group. You can also choose the operating system and runtime stack you want to use.

Once your App Service is created, you need to set up a deployment center that will automatically deploy your application every time you push a change to the main or master branch of your GitHub repository.

To do this, go to the Azure Portal, select your App Service, and click on the Deployment Center tab. Select GitHub as the source, and then select the repository and branch you want to deploy from. Click Save, and Azure will create a new GitHub Action file and install it on your repo.

At this point, you may run into an error during the build and deploy process if your solution has multiple projects. This is because the GitHub Action file that Azure produces works out of the box only if you have one project at the root level of your repository. However, if you have a solution with several projects, you’ll need to modify the GitHub Action file.

To modify the file, open it in your code editor, and change the build and publish steps to include only the project you want to deploy. In our example, we’re deploying a web app, so we only need to build and publish that project.

Once you’ve made the necessary changes to the GitHub Action file, commit your changes and push them to your repository. GitHub will then trigger the build and deployment process, and your web application will be deployed to Azure.

It’s worth noting that if your web application depends on other projects or packages, you’ll need to make sure that those dependencies are built and deployed along with the web app. You can do this by adding project references in your code editor and modifying the GitHub Action file accordingly.

Another issue you may encounter during deployment is that Azure doesn’t know which application to start if your main app is depending on a console app or another executable project. To fix this, you’ll need to set the startup command in the general settings tab of your App Service to point to a particular startup file. You can do this by specifying the name of the DLL file that contains the main entry point for your application.

In conclusion, deploying a web application to Azure can seem intimidating at first, but with the right tools and knowledge, it can be a straightforward process. By using GitHub Actions and the Azure Portal, you can set up automatic deployment of your web application to Azure in just a few steps.

Copyright © 2024 NimblePros - All Rights Reserved