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

.NET 8 GitHub Actions构建Blazor Hybrid Windows平台报NETSDK1112错误

解决GitHub Actions构建Blazor Hybrid项目时的NETSDK1112错误

可行排查与修复方案

1. 强制安装匹配版本的.NET SDK

Windows runner默认预装的SDK可能缺少项目所需的运行时包,在构建前显式指定SDK版本安装:

- name: Install .NET SDK
  uses: actions/setup-dotnet@v4
  with:
    dotnet-version: '8.0.x' # 替换为你的项目实际使用的.NET版本

2. 带RuntimeIdentifier的显式还原

在构建前单独执行还原命令,指定目标运行时,确保相关包被完整下载:

- name: Restore dependencies with runtime
  run: dotnet restore --runtime win-x64

3. 调整构建命令参数

构建时同时指定RuntimeIdentifier和自包含发布模式,避免依赖 runner 本地的运行时:

- name: Build Windows
  run: dotnet build --configuration Release --runtime win-x64 --self-contained true

4. 检查项目文件配置

确认.csproj中目标框架和运行时标识配置正确,比如:

<PropertyGroup>
  <TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
  <RuntimeIdentifiers>win-x64</RuntimeIdentifiers>
</PropertyGroup>

5. 清理缓存后重建

GitHub Actions的缓存可能残留旧依赖,添加清理步骤:

- name: Clean build artifacts
  run: |
    dotnet clean
    rmdir /s /q bin obj

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 18:08:09