Search code examples
azuregithubblazorgithub-actions

Deploying static Blazor web app from GitHub


I created a Blazor app with dotnet new blazor according to this tutorial and tried to deploy it on Azure, but this is not possible.

On Azure with the default settings I get the error message:

The app build failed to produce artifact folder: 'example/wwwroot'. Please ensure this property is configured correctly in your workflow file.

The Blazor app is in a subfolder example, so in the workflow I gave app_location: "/example/".

The output_location needs to be set to wwwroot (on AWS that is automatically correct, on Azure it has to be manually set).

Then it complains about missing index.html:

Failed to find a default file in the app artifacts folder (wwwroot). Valid default files: index.html,Index.html.

Solution

  • According to this MS Document, Azure Static Web app only supports Blazor WASM application and not the Blazor web app that gets created with dotnet new blazor command.

    I tried deploying the normal blazor web app in Azure static web app and received the same error code as yours, Then I created a sample Blazor WASM (WebAssembly standalone app) app and tried to deploy it in Azure Static Web app, It worked successfully.

    Blazor WASM app:-

    enter image description here

    Azure Static Web app Github Action Workflow:-

    name: Azure Static Web Apps CI/CD
    
    on:
      push:
        branches:
          - master
      pull_request:
        types: [opened, synchronize, reopened, closed]
        branches:
          - master
    
    jobs:
      build_and_deploy_job:
        if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.action != 'closed')
        runs-on: ubuntu-latest
        name: Build and Deploy Job
        steps:
          - uses: actions/checkout@v3
            with:
              submodules: true
              lfs: false
          - name: Build And Deploy
            id: builddeploy
            uses: Azure/static-web-apps-deploy@v1
            with:
              azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_POLITE_MUSHROOM_0EE789C03 }}
              repo_token: ${{ secrets.GITHUB_TOKEN }} 
              action: "upload"
              app_location: "/" 
              api_location: "" 
              output_location: "wwwroot" 
    
      close_pull_request_job:
        if: github.event_name == 'pull_request' && github.event.action == 'closed'
        runs-on: ubuntu-latest
        name: Close Pull Request Job
        steps:
          - name: Close Pull Request
            id: closepullrequest
            uses: Azure/static-web-apps-deploy@v1
            with:
              azure_static_web_apps_api_token: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN_POLITE_MUSHROOM_0EE789C03 }}
              action: "close"
    

    Output:-

    enter image description here

    enter image description here

    enter image description here

    In order to Depoy your Blazor Web app. Create Azure Web app service instead of Azure static Web app and deploy your app there, refer below:-

    enter image description here

    The Blazor Web app got deployed successfully:-

    enter image description here

    For Github Action Deployment in Azure Web App:-

    After the Web app is created> Visit Deployment Center > Select Source as Github > Your Blazor web app Github Repository and click Save:-

    The Web App deployment via Github Actions will start and succeed:-

    enter image description here