Deploy Blazor WASM with .NET 8 using GitHub Actions
Asked Answered
I

3

6

I created a fresh new Blazor WASM project targeting .NET 8 and want to deploy it to Azure Static Web App service using GitHub actions but I keep getting an error that tells me that .NET version 8 is not supported.

Has anyone been able to deploy a Blazor app targeting .NET 8 to Azure Static Web App service using GitHub actions?

Here's the GitHub action I'm using:

name: Deploy web app to Azure Static Web Apps

on:
  push:
    branches: [ "master" ]
  pull_request:
    types: [opened, synchronize, reopened, closed]
    branches: [ "master" ]

# Environment variables available to all jobs and steps in this workflow
env:
  APP_LOCATION: "/MyApp/" # location of your client code
  APP_ARTIFACT_LOCATION: "wwwroot" # location of client code build output
  AZURE_STATIC_WEB_APPS_API_TOKEN: ${{ secrets.AZURE_STATIC_WEB_APPS_API_TOKEN }} # secret containing deployment token for your static web app

permissions:
  contents: read

jobs:
  build_and_deploy_job:
    permissions:
      contents: read # for actions/checkout to fetch code
      pull-requests: write # for Azure/static-web-apps-deploy to comment on PRs
    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
      - name: Build And Deploy
        id: builddeploy
        uses: Azure/static-web-apps-deploy@v1
        with:
          azure_static_web_apps_api_token: ${{ env.AZURE_STATIC_WEB_APPS_API_TOKEN }} # secret containing api token for app
          repo_token: ${{ secrets.GITHUB_TOKEN }} # Used for Github integrations (i.e. PR comments)
          action: "upload"
          ###### Repository/Build Configurations - These values can be configured to match you app requirements. ######
          # For more information regarding Static Web App workflow configurations, please visit: https://aka.ms/swaworkflowconfig
          app_location: ${{ env.APP_LOCATION }}
          api_location: ${{ env.API_LOCATION }}
          app_artifact_location: ${{ env.APP_ARTIFACT_LOCATION }}
          ###### End of Repository/Build Configurations ######

  close_pull_request_job:
    permissions:
      contents: none
    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: ${{ env.AZURE_STATIC_WEB_APPS_API_TOKEN }} # secret containing api token for app
          action: "close"
Institutionalize answered 29/8, 2023 at 18:19 Comment(0)
R
4

I went round-and-round on Github trying to find the answer.

  • The Github action Azure/static-web-apps-deploy@v1 uses a closed source Docker container.

  • Said docker container uses: Oryx

Oryx added support for .NET 8 preview 7, at the time of writing, 5 days ago.

But the closed source docker container doesn't seem to use the latest version of Oryx.

So if you want to deploy with the Github action that Azure Static Web Apps created when you connected your repository, well, just wait longer.

If you want to deploy now, try SWA CLI. I'll be trying this later in the week and may add some more to this.

Ralfston answered 31/8, 2023 at 3:10 Comment(0)
A
0

It works, you need to understand properly. Here App_Location means where your code exists under the root of repo, for example in my case Root is UnWell under which it has folder called Medicines,under which Medicines.CLientWasm, so you had to mention relative path next to root as "Medicines/Medicines.CLientWasm". In All documention of @microsoft they are saying client it means client is a folder of wasm app. they should mention that but its missed. Even I spent more than 5 days dieing for this,then discovered. Github actions all works fine, I tested

enter image description here

Amparoampelopsis answered 20/12, 2023 at 4:7 Comment(0)
P
0

You can do custom build to match your needs and simply deploy using Azure/static-web-apps-deploy@v1 as shown below.

- name: Publish Blazor Project
  run: dotnet publish ./Web/Web.csproj -c:Release --no-restore -o dist/Web --nologo

- uses: Azure/static-web-apps-deploy@v1
  with:
    azure_static_web_apps_api_token: ${{ env.AZURE_STATIC_WEB_APPS_API_TOKEN }}
    action: "upload"
    skip_app_build: true
    app_location: "dist/Web/wwwroot"
    api_location: ""
    output_location: ""

If you see above, I have set skip_app_build: true and did mu custom build in previous steps in my job and simply set the published file path in app_location.

The key thing here is you have control over building your apps as needed.

I have a detailed write up here - https://ilovedotnet.org/blogs/blazor-wasm-publishing-to-azure-static-web-apps/

Parthen answered 28/7 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.