You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从GitHub部署静态Blazor Web应用至Azure遇问题求助

Blazor应用部署Azure失败的解决办法

问题描述

通过dotnet new blazor创建Blazor应用,部署到Azure时先后碰到两个问题:

  1. 默认配置下报错:

应用构建未生成产物文件夹:'example/wwwroot'。请确保在工作流文件中正确配置此属性。

  1. 设置app_location: "/example/"和output_location: "wwwroot"后,又报错:

未在应用产物文件夹(wwwroot)中找到默认文件。有效的默认文件为:index.html,Index.html。

解决步骤

1. 明确Blazor应用类型及正确输出目录

从.NET 8开始,dotnet new blazor默认创建的是Blazor Web App(混合渲染模式),它的编译输出目录并非wwwroot:

  • 若使用Azure静态Web Apps部署,正确输出目录为bin/Release/{你的.NET版本}/publish/wwwroot(例如bin/Release/net8.0/publish/wwwroot)
  • 若是Blazor WebAssembly应用(通过dotnet new blazorwasm创建),输出目录为bin/Release/{你的.NET版本}/wwwroot
  • 若是Blazor Server应用(dotnet new blazorserver),它属于服务器端渲染,没有静态index.html,部署时无需指定wwwroot作为输出目录

2. 调整Azure部署工作流配置

针对Azure静态Web Apps:

修改工作流文件(azure-static-web-apps-*.yml)中的参数:

  • app_location: "example"(不要加末尾斜杠)
  • output_location: "bin/Release/net8.0/publish/wwwroot"(替换为你实际使用的.NET版本,比如net7.0)
  • 确保工作流包含正确的构建命令:
app_build_command: "dotnet publish -c Release -o bin/Release/net8.0/publish"

针对Azure App Service:

无需指定output_location,直接在部署任务中把项目路径设为example/你的项目名.csproj,构建命令使用dotnet publish -c Release即可,App Service会自动识别发布后的文件结构。

3. 本地验证构建输出

先在本地执行构建命令,确认输出目录中存在index.html:

cd example
dotnet publish -c Release

随后查看bin/Release/{你的.NET版本}/publish/wwwroot目录,若没有index.html,检查项目的Program.cs和项目文件配置,确保已启用静态文件服务。

内容的提问来源于stack exchange,提问作者user66554

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.02 05:03:29