Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (161).NET Core  (29).NET MAUI  (65)Angular  (74)ASP.NET  (50)ASP.NET Core  (79)ASP.NET MVC  (88)Azure  (36)Blazor  (153)DocIO  (23)Essential JS 2  (86)Essential Studio  (174)File Formats  (29)Flutter  (123)JavaScript  (187)Microsoft  (113)PDF  (67)React  (62)Succinctly series  (128)Syncfusion  (612)TypeScript  (32)Uno Platform  (3)UWP  (4)Vue  (40)Webinar  (35)Windows Forms  (59)WinUI  (53)WPF  (138)Xamarin  (156)XlsIO  (25)Other CategoriesBarcode  (5)BI  (29)Bold BI  (5)Build conference  (6)Business intelligence  (54)Button  (4)C#  (120)Chart  (57)Cloud  (12)Company  (445)Dashboard  (8)Data Science  (3)Data Validation  (6)DataGrid  (55)Development  (403)Doc  (7)DockingManager  (1)eBook  (96)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (23)Extensions  (18)File Manager  (4)Gantt  (11)Gauge  (11)Git  (4)Grid  (28)HTML  (11)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (314)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (30)Performance  (9)PHP  (1)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (7)Road Map  (10)Scheduler  (37)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (23)Solution Services  (3)Spreadsheet  (11)SQL  (8)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (11)Tips and Tricks  (92)UI  (226)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (23)Visual Studio Code  (17)Web  (377)What's new  (213)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Share on twitter
Share on facebook
Share on linkedin
Deploying a Blazor Server-Side Application to Azure App Service Using GitHub Actions

Deploying a Blazor Server-Side Application to Azure App Service Using GitHub Actions

GitHub Actions is a CI/CD platform that helps us to automate the deployment process of applications using the GitHub repository. We can build, test, and deploy our applications to the Azure App Service using GitHub Actions. This blog will demonstrate the procedure to deploy a Blazor server-side app to the Azure App Service using GitHub Actions.

Prerequisites

Before starting to create and deploy the Blazor application, you need to have the following tools installed:

Step 1: Create Azure Web App in Azure App Service

Microsoft’s Azure App Service is a platform as a service (PaaS) solution. We can use it to host web apps, REST APIs, and backend services for mobile apps. In this blog, we use Azure App Service to host a Blazor server-side application as a web app.

First, open the Azure portal and select Azure App Service. Then, click Create to create an Azure web app.

After that, you need to enter several details to finalize the Azure web app.

Creating Azure Web App in Azure App Service

In the previously pictured form, select the resource group first. If there isn’t a resource group, create a resource group by clicking Create New. Second, provide a unique name for the app. Third, select the runtime stack to build and run the application. For this example, I select .NET 6 as the runtime stack for the Blazor server-side application, Linux as the operating system, and East Asia as the region.

Once the application is created, click on the application name. Now, you will see an option named Get publish profile. Make sure to download the published profile from there and save it locally, since we will use it in one of the next steps with the GitHub Repository.

Click on Get publish profile

Step 2: Create the Blazor Server-Side Application

In this step, we create a Blazor server-side application using Visual Studio 2022. First, open Visual Studio and create a new project with the Blazor Server App template. Then, select .NET 6 as the framework for this project.

Creating the Blazor Server-Side Application

After creating the project, run it, and check that everything is working.

Step 3: Configure the YAML File for GitHub Workflow

Now, we create the YAML file to create the GitHub workflow for GitHub Actions. First, navigate to the Blazor application project folder created in the previous step. Then, create a directory named .github followed by a directory named workflows inside the .github directory.

After that, create a YAML file named demo.yml inside the workflows directory and update it with the following code.

name: Build and deploy Blazor App
# use this 'on' to trigger the workflow
on:
  push: # trigger when pushing the commits into main branch
    branches:
      - main
  workflow_dispatch:

jobs:
  build:
    runs-on: windows-latest  # OS or machine to run each job
    steps: # steps - series of tasks to run the job
      - uses: actions/checkout@v2#Setup .NET Core SDK
      - name: Set up .NET Core
        uses: actions/setup-dotnet@v1
        with:# Use latest version of dotnet 6
          dotnet-version: '6.0.x'# include pre-release of dotnet
          include-prerelease: true
       
      - name: Build with dotnet# run the command for build the dotnet app
        run: dotnet build --configuration Release

      - name: dotnet publish# run the command to pack the build files and dependencies into folder for deployment
        run: dotnet publish -c Release -o ${{env.DOTNET_ROOT}}/myapp

      - name: Upload artifact for deployment job#Reference a specific upload artifact
        uses: actions/upload-artifact@v2

        with:
          name: .net-app
          path: ${{env.DOTNET_ROOT}}/myapp

  deploy:
    runs-on: windows-latest
    needs: build #contains the output from the build job#set environment
    environment:
      name: 'Production'# use deploy-to-webapp step in the job and look at the output of the dependent job. Then find the webapp-url and set it for URL in the environment
      url: ${{ steps.deploy-to-webapp.outputs.webapp-url }}

    steps:
      - name: Download artifact from build job#Reference a specific download artifact from build job
        uses: actions/download-artifact@v2
        with:
          name: .net-app

      - name: Deploy to Azure Web App
        id: deploy-to-webapp# Reference the deploy web app
        uses: azure/webapps-deploy@v2
        with:#use app name
          app-name: 'blazordemo-git'
          slot-name: 'Production'#use publish profile from the GitHub secrets
          publish-profile: ${{ secrets.AZUREAPPSERVICE_PUBLISHPROFILE }}
          package: .

In the previous script, the name property in the first line is issued to define the GitHub workflow name. Then, the trigger conditions are defined to execute the workflow. Based on these configurations, the workflow will be triggered when a commit is pushed into the main branch.

After that, a new job is initialized to build the Blazor server-side application. We include the necessary commands to build the application. Finally, a new deployment job is created to deploy the application to the Azure App Service as a web app. In this example, I have used secrets from the publish profile. I will show you how to create this in the next step. The publish profile contains information and settings used to deploy the application to Azure.

Step 4: Configure the Secrets and Deploy the Application

In this step, we create a GitHub repository for the Blazor application and add secret data to it. For this, we need to use the publish profile downloaded in step 1.

Configuring the Secrets

After adding the secret data, we push the changes to the GitHub repository. Then, the action will trigger and start the GitHub workflow. It will run two jobs, one to build and another to deploy the application. You can check the status of the action in the Action tab, as shown in the following screenshot.

Push the changes to the GitHub repository

Once the application is deployed, go to the portal and check the created web app.

Check the created web app
You will see the status is running. If you need to stop this application, click Stop.

Click the URL to check the website.
Deploying Blazor server-side application to Azure App service using GitHub Actions

Conclusion

This article discussed how to deploy a Blazor server-side application to the Azure App Service using GitHub Actions. With the increasing popularity of GitHub Actions and Blazor applications, it is an advantage to understand how to automate your CI/CD process by combining them.

I hope this article helps you in your next Blazor project. Thank you for reading.

Syncfusion’s Blazor component suite offers over 70 UI components. They work with both server-side and client-side (WebAssembly) hosting models seamlessly. Use them to build marvelous apps!

If you have any questions or comments, you can contact us through our support forumssupport portal, or feedback portal. We are always happy to assist you!

Related blogs

Tags:

Share this post:

Share on twitter
Share on facebook
Share on linkedin
Popular Now

Be the first to get updates

Subscribe RSS feed
Scroll To Top