如何解决gitlab CI中的ASP.NET Core项目构建错误:错误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
,
听起来您的CI / CD机器需要在其上安装最新版本的.NET Core SDK。或者将您的项目投影到构建计算机上安装的.NET Core版本,基于该错误,该版本似乎是v2.1。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。