c# - gitlab CI 中的 ASP.NET 核心项目构建错误:错误 NETSDK1045:当前的 .NET SDK 不支持针对 .NET Core 5.0
问题描述
当我使用这个 CI 配置文件时,从 gitlab 管道获取构建错误:
/usr/share/dotnet/sdk/2.1.809/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(137,5):错误NETSDK1045:当前的.NET SDK不支持定位.NET核心 5.0。以 .NET Core 2.1 或更低版本为目标,或者使用支持 .NET Core 5.0 的 .NET SDK 版本。
image: microsoft/dotnet:latest
variables:
# 1) Name of directory where restore and build objects are stored.
OBJECTS_DIRECTORY: 'obj'
# 2) Name of directory used for keeping restored dependencies.
NUGET_PACKAGES_DIRECTORY: '.nuget'
# 3) A relative path to the source code from project repository root.
SOURCE_CODE_PATH: '*/*/'
# ### Define stage list
stages:
- build
- test
# ### Define global cache rule
cache:
# Per-stage and per-branch caching.
key: "$CI_JOB_STAGE-$CI_COMMIT_REF_SLUG"
paths:
# Specify three paths that should be cached:
#
# 1) Main JSON file holding information about package dependency tree, packages versions,
# frameworks etc. It also holds information where to the dependencies were restored.
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/project.assets.json'
# 2) Other NuGet and MSBuild related files. Also needed.
- '$SOURCE_CODE_PATH$OBJECTS_DIRECTORY/*.csproj.nuget.*'
# 3) Path to the directory where restored dependencies are kept.
- '$NUGET_PACKAGES_DIRECTORY'
# 'pull-push' policy is the default cache policy, you do not have to specify it explicitly.
policy: pull-push
# ### Restore project dependencies
before_script:
- 'dotnet restore --packages $NUGET_PACKAGES_DIRECTORY'
build:
stage: build
script:
- 'dotnet build --no-restore'
tests:
stage: test
# ### Run the tests
script:
- 'dotnet test --no-restore'
解决方案
我们应该准确地编写 dotnet 版本:
利用
image: mcr.microsoft.com/dotnet/core/sdk:5.0
代替
image: microsoft/dotnet:latest
推荐阅读
- swift - 显示动画时在后台加载场景
- android - 何时/如何创建/销毁房间数据库
- excel - vba 代码耗时过长(偏移)在 excel 中运行的代码以填充工作表的行列
- python - IndexError,Python 绘图
- c# - EPPlus Excel 相关日期上次修改
- replace - 修复文本文件中多余的空格
- python - 从另一个数据框中删除具有相同值的行
- mongodb - 仅安装 Mongo 客户端/Shell - 在 Windows 上不安装 MongoDB
- python - 芹菜嵌套和弦未按正确顺序调用回调
- python - 如何创建熊猫数据框以在 Python 中导出此字典?