Azure部署槽缺失.NET 7 SDK致部署失败?安装方法及排查
.NET7部署槽缺失SDK问题:原因与解决办法
问题根源
流水线代理与部署槽服务器是完全独立的两个环境:
- 流水线中
Use .NET Core任务安装的.NET7 SDK仅存在于流水线运行的代理机器上,不会自动同步到部署槽所在的目标服务器。 - 部署阶段执行DbUp脚本时,是在部署槽服务器环境中运行,该环境仅装有.NET3.1、6.0的运行时,缺少.NET7运行时,因此触发
Microsoft.NETCore.App 7.0.0缺失的错误。
解决方法:在部署槽服务器安装.NET7
1. Kudu控制台手动安装
- 进入目标App Service的高级工具(Kudu),打开PowerShell调试控制台。
- 执行以下命令安装.NET7运行时:
# 下载.NET7运行时安装包 Invoke-WebRequest -Uri "https://download.visualstudio.microsoft.com/download/pr/8f08bebf-8851-4cb3-9a16-7e800004867a/38369e796f1c61272732532e5b7c4fc3/dotnet-runtime-7.0.0-win-x64.exe" -OutFile "dotnet-runtime.exe" # 静默安装 .\dotnet-runtime.exe /quiet /norestart
2. 流水线自动安装任务
在发布流水线中添加PowerShell任务,自动在部署服务器安装.NET7:
- 选择Azure PowerShell任务,目标指向部署槽对应的App Service。
- 脚本内容:
# 检查.NET7运行时是否已安装 if (-not (Test-Path "C:\Program Files\dotnet\shared\Microsoft.NETCore.App\7.0.*")) { # 创建临时目录 New-Item -Path "C:\temp" -ItemType Directory -Force | Out-Null # 下载安装包 Invoke-WebRequest -Uri "https://download.visualstudio.microsoft.com/download/pr/8f08bebf-8851-4cb3-9a16-7e800004867a/38369e796f1c61272732532e5b7c4fc3/dotnet-runtime-7.0.0-win-x64.exe" -OutFile "C:\temp\dotnet-runtime.exe" # 静默安装 Start-Process -FilePath "C:\temp\dotnet-runtime.exe" -ArgumentList "/quiet /norestart" -Wait }
3. App Service扩展安装
- 进入App Service的扩展页面,点击「添加」,搜索
.NET Runtime,选择.NET7版本完成安装。此方式由Azure托管维护,无需手动操作。
4. 自包含部署(无需服务器预安装)
修改DbUp项目的.csproj文件,配置为自包含发布,打包时将.NET7运行时一起包含:
<PropertyGroup> <SelfContained>true</SelfContained> <RuntimeIdentifier>win-x64</RuntimeIdentifier> <!-- 可选:打包为单文件 --> <PublishSingleFile>true</PublishSingleFile> </PropertyGroup>
发布后直接部署即可,无需服务器提前安装.NET7。
内容的提问来源于stack exchange,提问作者Matt Searles
相关产品推荐
相关产品推荐

