Docker 构建失败,当前 .NET SDK 不支持面向 .NET Core 2.1
Posted
技术标签:
【中文标题】Docker 构建失败,当前 .NET SDK 不支持面向 .NET Core 2.1【英文标题】:Docker build fails with the current .NET SDK does not support targeting .NET Core 2.1 【发布时间】:2018-11-20 02:57:52 【问题描述】:在 Windows 10 上执行此操作:
>docker-compose -f docker-compose.yml build
Building MyApprestapi
Step 1/17 : FROM microsoft/aspnetcore:2.0 AS base
---> 6237a4750408
Step 2/17 : WORKDIR /app
Removing intermediate container ae0057e8752c
---> d422fca6b533
Step 3/17 : EXPOSE 11001
---> Running in 70f6f9a9d052
Removing intermediate container 70f6f9a9d052
---> 673d1c1d8f34
Step 4/17 : FROM microsoft/aspnetcore-build:2.0 AS build
---> f5f1d9a332af
Step 5/17 : WORKDIR /src
Removing intermediate container 0c5e68914dfd
---> 035e0d5467bf
Step 6/17 : COPY MyAppPipeline.sln ./
---> b0ccbf6431b4
Step 7/17 : COPY MyAppRestApi/MyAppRestApi.csproj MyAppRestApi/
---> 3216ad77f880
Step 8/17 : RUN dotnet restore -nowarn:msb3202,nu1503
---> Running in f0b9fa8dbbd4
C:\Program Files\dotnet\sdk\2.1.200\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(135,5): error : The current .NET SDK does not support targeting .NET Core 2.1. Either target .NET Core 2.0 or lower, or use a version of the .NET SDK that supports .NET Core 2.1. [C:\src\MyAppRestApi\MyAppRestApi.csproj]
ERROR: Service 'MyApprestapi' failed to build: The command 'cmd /S /C dotnet restore -nowarn:msb3202,nu1503' returned a non-zero code: 1
如果我这样做:
>dotnet --info
.NET Core SDK(反映任何 global.json):版本:2.1.300 提交:adab45bf0c
运行时环境:操作系统名称:Windows 操作系统版本:10.0.17134 操作系统平台:Windows RID:win10-x64 基本路径:C:\Program 文件\dotnet\sdk\2.1.300\
主机(用于支持):版本:2.1.0 提交:caa7b7e2ba
.NET Core SDK 已安装: 1.0.0-preview2-003131 [C:\Program Files\dotnet\sdk] 2.1.2 [C:\Program Files\dotnet\sdk] 2.1.104 [C:\Program Files\dotnet\sdk] 2.1.300 [C:\Program Files\dotnet\sdk]
.NET Core 运行时安装:Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [C:\Program 文件\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 1.0.1 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.3 [C:\Program 文件\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.0.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 2.1.0 [C:\Program 文件\dotnet\shared\Microsoft.NETCore.App]
要安装其他 .NET Core 运行时或 SDK:https://aka.ms/dotnet-download
【问题讨论】:
【参考方案1】:问题是我在创建项目时生成的 DockerFile。 我不得不使用这里列出的替代品:
https://github.com/dotnet/dotnet-docker
microsoft/dotnet:2.1-aspnetcore-runtime
microsoft/dotnet:2.1-sdk
【讨论】:
以上是关于Docker 构建失败,当前 .NET SDK 不支持面向 .NET Core 2.1的主要内容,如果未能解决你的问题,请参考以下文章
Azure-Pipeline Build 结果:当前的 .NET SDK 不支持面向 .NET Core 3.1
ASP.NET Core 3.1 Angular Web App 在 Windows 上构建和运行,但在 Mac OSX 和 Docker 上失败
具有文件内容的 .Net 资源使 docker build 失败