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

Azure App Service部署.NET 8预览版Linux应用启动失败求助

.NET 8预览版Linux容器在Azure App Service启动失败:RuntimeConfig指向RC版本但容器仅含Preview7

问题描述

我在Azure App Service的Linux容器上部署.NET 8预览版应用,容器无法启动。容器内置的是.NET 8 Preview7(8.0.0-preview.7.23375.6),但应用启动时要求RC1版本(8.0.0-rc.1.23419.4),导致端口8080无响应被终止。

我已经把项目里的RC包替换成了Preview7的包(比如8.0.0-preview.7.23375.9),但发布后生成的Test.Api.runtimeconfig.json里依然指向RC版本的Microsoft.AspNetCore.App,而项目文件里并没有直接声明这个RC版本的依赖。

想解决两个问题:

  • 能不能手动在Linux容器里安装8.0.0-rc.1版本?
  • 能不能修改GitHub Actions的YAML脚本,在构建阶段指定安装Preview7版本,避免生成指向RC的runtimeconfig?

相关日志

容器日志

2023-09-17T20:25:27.314076959Z The following frameworks were found:
2023-09-17T20:25:27.314080459Z   8.0.0-preview.7.23375.6 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
2023-09-17T20:25:27.314084859Z
2023-09-17T20:25:27.314088060Z Learn more:
2023-09-17T20:25:27.314103160Z https://aka.ms/dotnet/app-launch-failed
2023-09-17T20:25:27.314106760Z
2023-09-17T20:25:27.314110060Z To install missing framework, download:
2023-09-17T20:25:27.314113460Z https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=8.0.0-rc.1.23419.4&arch=x64&rid=linux-x64&os=debian.12
2023-09-17T20:25:28.143Z ERROR - Container mytestsite_0_6514069e for site mytestsite has exited, failing site start
2023-09-17T20:25:28.165Z ERROR - Container mytestsite_0_6514069e didn't respond to HTTP pings on port: 8080, failing site start. See container logs for debugging.
2023-09-17T20:25:28.168Z INFO  - Stopping site mytestsite because it failed during startup.

应用日志

2023-09-17T20:05:29.1782264 Trying to find the startup DLL name...
2023-09-17T20:05:29.1785581 Found the startup D name: Test.Api.dll
2023-09-17T20:05:29.1786987 Running the command: dotnet "Test.Api.dll"
2023-09-17T20:05:29.2267788 You must install or update .NET to run this application.
2023-09-17T20:05:29.2268172 App: /home/site/wwwroot/Test.Api.dll
2023-09-17T20:05:29.226821 Architecture: x64
2023-09-17T20:05:29.227199 Framework: 'Microsoft.NETCore.App', version '8.0.0-rc.1.23419.4' (x64)
2023-09-17T20:05:29.227326 .NET location: /usr/share/dotnet/

Test.Api.runtimeconfig.json片段

{
  "name": "Microsoft.AspNetCore.App",
  "version": "8.0.0-rc.1.23421.29"
}

解决方案

1. 锁定项目的框架版本(推荐)

问题根源是某个间接依赖的包引入了RC版本的ASP.NET Core,导致runtimeconfig自动生成了RC版本要求。直接在项目文件里强制指定框架版本:

  • 打开项目的.csproj文件,添加以下配置:
<PropertyGroup>
  <TargetFramework>net8.0</TargetFramework>
  <!-- 锁定.NET Core运行时版本为容器内置的Preview7 -->
  <RuntimeFrameworkVersion>8.0.0-preview.7.23375.6</RuntimeFrameworkVersion>
  <!-- 锁定ASP.NET Core运行时版本为你使用的Preview7包 -->
  <AspNetCoreRuntimeVersion>8.0.0-preview.7.23375.9</AspNetCoreRuntimeVersion>
</PropertyGroup>
  • 清理NuGet缓存并重新构建:
dotnet nuget locals all --clear
dotnet restore
dotnet publish -c Release

2. 修改GitHub Actions构建脚本,指定Preview7 SDK

如果用GitHub Actions构建,确保构建环境使用和容器一致的Preview7 SDK,避免生成不匹配的runtimeconfig:

jobs:
  build-and-deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      
      - name: Setup .NET 8 Preview7 SDK
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: '8.0.100-preview.7.23376.3' # 对应Preview7的SDK版本
          
      - name: Restore dependencies
        run: dotnet restore
        
      - name: Build project
        run: dotnet build --configuration Release --no-restore
        
      - name: Publish project
        run: dotnet publish --configuration Release --no-build --output ./publish
        
      # 后续部署到Azure App Service的步骤

3. 手动在容器内安装RC1版本(仅临时调试)

Azure App Service的容器是无状态的,重启后手动安装的版本会丢失,仅适合临时验证:

  1. 在Azure Portal进入App Service的开发工具 > SSH,连接到容器终端。
  2. 运行以下命令下载并安装RC1 runtime:
# 下载RC1 runtime包
wget https://download.visualstudio.microsoft.com/download/pr/86e0e2b3-040c-475a-9f41-86e0a1114b4c/0a7a3f5f447f5b4a1e839dad29671300/dotnet-runtime-8.0.0-rc.1.23419.4-linux-x64.tar.gz
# 创建对应的版本目录
mkdir -p /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.0-rc.1.23419.4
# 解压到指定目录
tar zxf dotnet-runtime-8.0.0-rc.1.23419.4-linux-x64.tar.gz -C /usr/share/dotnet/shared/Microsoft.NETCore.App/8.0.0-rc.1.23419.4

安装完成后重启应用即可临时运行,但重启容器后需要重新安装。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.10 13:32:03