Azure / static-web-apps

Azure Static Web Apps. For bugs and feature requests, please create an issue in this repo. For community discussions, latest updates, kindly refer to the Discussions Tab. To know what's new in Static Web Apps, visit https://aka.ms/swa/ThisMonth
https://aka.ms/swa
MIT License
330 stars 57 forks source link

Cannot deploy .NET 8 Blazor App to an Azure Static Web App using Azure DevOps Pipeline #1392

Closed mattfrear closed 10 months ago

mattfrear commented 10 months ago

Describe the bug I cannot deploy a brand new .NET 8 Blazor app to Azure Static Web apps using Azure Devops.

A clear and concise description of what the bug is.

To Reproduce Steps to reproduce the behavior:

  1. Go to Visual Studio 2022
  2. Create a New Project -> Blazor Web App -> BlazorApp1
  3. (It doesn't matter which Interactive render mode I use, I can't make any of them work. For simplicity, let's choose Server)
  4. Push the code to an Azure DevOps repository
  5. Create a yaml pipeline (I have truncated bits for privacy, but you get the idea):
trigger: none

stages:
- stage: 'Deploy_Web'
  displayName: 'Deploy Static Web App'
  jobs:
  - job: DeployWeb
    displayName: Deploy Web
    pool:
      vmImage: ubuntu-latest
    steps:
    - checkout: self
      submodules: true
    - task: AzureStaticWebApp@0
      inputs:
        azure_static_web_apps_api_token: $(AZURE_STATIC_WEB_APPS_API_TOKEN)
        app_location: "BlazorApp1" # App source code path
        output_location: "wwwroot" # Built app content directory - optional

Outcome The AzureStaticWebApp@0 module errors with:

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

Expected behavior I expect the app to deploy and run.

I have experimented and tried adding a static index.html to my wwwroot folder, but if I do that then the deploy succeeds - I can see the index.html file. But it's not successful as I can't run my Blazor app.

Is there a way to tell the AzureStaticWebApp@0 module to look for something other than an index.html file? Although, I'm not sure what that should be.

FYI when I publish the VS solution locally, this is the content of my published folder: image and image

thomasgauvin commented 10 months ago

Hi @mattfrear, you are attempting to deploy a Blazor Web App which requires to be hosted on a server (such as App Service) and can't be hosted on Static Web Apps. To host Blazor on Static Web Apps, you must use the WebAssembly mode, which is documented in our docs https://learn.microsoft.com/en-us/azure/static-web-apps/deploy-blazor and in this blog post https://techcommunity.microsoft.com/t5/apps-on-azure-blog/build-and-deploy-net-8-blazor-wasm-apps-with-serverless-apis/ba-p/3988412. This mode compiles to static assets that can be hosted on Azure Static Web Apps

mattfrear commented 10 months ago

Hi Thomas. Thank you for that. I realised that I had to use WebAssembly after I raised this issue. I was attempting to do so by choosing the WebAssembly Interactive Render mode in the "Blazor Web App" project template.

I didn't know I was supposed to use the "Blazor WebAssembly Standalone App" project template instead, as per your blog post. Thanks! I will try again using that template, as well as read through the rest of your blob post.