在Docker中运行时出错找不到指定的框架'Microsoft.AspNetCore.App'版本'2.1.6'。上

时间:2018-12-03 10:31:36

标签: docker .net-core

我尝试在Docker中运行带有GenericHost的项目。它可以在我的计算机上本地运行控制台应用程序,并且可以正确构建。如果我删除一些代码并删除软件包Microsoft.AspNetCore.App,它将运行良好,因此在Docker上运行该问题似乎与该软件包无关。

错误消息:

It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.6' was not 
found.
- Check application dependencies and target a framework version installed at:
  /usr/share/dotnet/
- Installing .NET Core prerequisites might help resolve this problem:
  https://go.microsoft.com/fwlink/?LinkID=798306&clcid=0x409
- The .NET Core framework and SDK can be installed from:
  https://aka.ms/dotnet-download
The target process exited without raising a CoreCLR started event. Ensure that the target process is configured to use .NET Core. This may be expected if the target process did not run on .NET Core.
The program '[24] dotnet' has exited with code 150 (0x96).
The program 'dotnet' has exited with code 150 (0x96).

下面是我的DockerFile:

FROM microsoft/dotnet:2.1-runtime AS base
WORKDIR /app

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ../TestProj/TestProj.csproj ../TestProj/
RUN dotnet restore ../TestProj/TestProj.csproj
COPY . .
WORKDIR /src/../TestProj
RUN dotnet build TestProj.csproj -c Release -o /app

FROM build AS publish
RUN dotnet publish TestProj.csproj -c Release -o /app

FROM base AS final
WORKDIR /app
COPY --from=publish /app .
ENTRYPOINT ["dotnet", "TestProj.dll"]

由于需要引用,原始Docker文件还包含一些“ COPY”,但请在此处进行编辑。

更新 本地机器:

dotnet --info
.NET Core SDKs installed:
1.1.9 [C:\Program Files\dotnet\sdk]
1.1.11 [C:\Program Files\dotnet\sdk]
2.1.201 [C:\Program Files\dotnet\sdk]
2.1.202 [C:\Program Files\dotnet\sdk]
2.1.300 [C:\Program Files\dotnet\sdk]
2.1.402 [C:\Program Files\dotnet\sdk]
2.1.500 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
Microsoft.AspNetCore.All 2.1.0 [C:\Program 
Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.4 [C:\Program 
Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.All 2.1.6 [C:\Program     Files\dotnet\shared\Microsoft.AspNetCore.All]
Microsoft.AspNetCore.App 2.1.0_old [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.4_old [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
Microsoft.NETCore.App 1.0.11 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.0.13 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 1.1.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.7 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
Microsoft.NETCore.App 2.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]

在我的本地docker上:

Host (useful for support):
Version: 2.1.6
Commit:  3f4f8eebd8

.NET Core SDKs installed:
No SDKs were found.

.NET Core runtimes installed:
Microsoft.NETCore.App 2.1.6 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download

1 个答案:

答案 0 :(得分:1)

显然,如果将项目创建为控制台应用程序并使用nuget Microsoft.aspnetcore.app,则存在问题。我重新创建了该项目,但将其作为Web应用程序运行,然后它开始工作。也许是显而易见的,因为它是一个“网络小工具”,但它并没有让我脑海中浮现。

我应该注意,我在使用docker镜像时遇到了一些问题,必须再次使用特定版本再次提取dotnet docker-image。

docker pull microsoft/dotnet:2.1-aspnetcore-runtime

它不会加载/启动正确的dotnet版本。