简体   繁体   English

gitlab CI 中的 ASP.NET 核心项目构建错误:错误 NETSDK1045:当前 .NET SDK 不支持面向 .NET Core 5.0

[英]ASP.NET core project build error in gitlab CI : error NETSDK1045: The current .NET SDK does not support targeting .NET Core 5.0

When I use this CI config file get build error from gitlab pipeline :当我使用这个 CI 配置文件时,从 gitlab 管道中得到构建错误:

/usr/share/dotnet/sdk/2.1.809/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(137,5): error NETSDK1045: The current .NET SDK does not support targeting .NET Core 5.0. /usr/share/dotnet/sdk/2.1.809/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.TargetFrameworkInference.targets(137,5):错误NETSDK1045:当前.NET SDK不支持.NET核心 5.0。 Either target .NET Core 2.1 or lower, or use a version of the .NET SDK that supports .NET Core 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'

We should write dotnet version exactly:我们应该准确地编写 dotnet 版本:

use

image: mcr.microsoft.com/dotnet/core/sdk:5.0

instead of代替

image: microsoft/dotnet:latest

It sounds like your CI/CD machine needs the latest version of the .NET Core SDK installed on it.听起来您的 CI/CD 机器需要安装最新版本的 .NET Core SDK。 Or peg you project to the version of .NET Core installed on your build machine, which appears to be v2.1 based on the error.或者将您的项目与构建机器上安装的 .NET Core 版本挂钩,根据错误,该版本似乎是 v2.1。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 NETSDK1045 当前的 .NET SDK 不支持面向 .NET Core 3.1 - 由缓存引起? - NETSDK1045 The current .NET SDK does not support targeting .NET Core 3.1 - Caused by Cache? 无效 - 错误 NETSDK1045:当前 .NET SDK 不支持定位 .NET 6.0 - None worked - Error NETSDK1045: The current .NET SDK does not support targeting .NET 6.0 使用 Blazor Asp.NetCore 托管模板时获取“NETSDK1045 当前 .NET SDK 不支持 .NET Core 3.0 作为目标” - Getting “NETSDK1045 The current .NET SDK does not support .NET Core 3.0 as a target” when using Blazor Asp.NetCore hosted template 当前的 .NET SDK 不支持面向 .NET Core 2.2 - The current .NET SDK does not support targeting .NET Core 2.2 错误:当前的.NET SDK不支持定位.NET Standard 2.0 - Error: The current .NET SDK does not support targeting .NET Standard 2.0 当前的 .NET SDK 不支持针对 .NET Core 2.1。 目标 .NET Core 1.1 或更低版本 - The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 1.1 or lower 当前的.NET SDK不支持定位.NET Core 2.2。 (SDK 2.2.202) - The current .NET SDK does not support targeting .NET Core 2.2. (SDK 2.2.202) VintaSoft Imaging .NET SDK 11.0 with asp.net core api 5.0 give me swagger internal error - VintaSoft Imaging .NET SDK 11.0 with asp.net core api 5.0 give me swagger internal error Azure 构建管道 NuGet 还原错误 NETSDK1045 - Azure build pipeline NuGet Restore error NETSDK1045 ASP.NET Core docker构建错误 - ASP.NET Core docker build error
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM