我有一个使用.net core 2.1编译的项目
该项目非常简单:
Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.App" Version="2.1.1" />
</ItemGroup>
它可以在主机上编译并正常运行。
我制作了一个docker镜像:
FROM microsoft/dotnet:2.1-sdk AS build
COPY ./Test /src/Test
WORKDIR /src/Test
RUN dotnet build -c Release -o /app
FROM build AS publish
RUN dotnet publish -c Release -o /app --no-restore
FROM microsoft/dotnet:2.1-runtime AS final
WORKDIR /app
COPY --from=publish /app .
CMD ["dotnet", "Test.dll"]
它构建正确,没有警告。
但是当我执行它时:
# dotnet Test.dll
It was not possible to find any compatible framework version
The specified framework 'Microsoft.AspNetCore.App', version '2.1.1' 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
因此,当我检查框架版本(我使用dotnet:2.1-runtime构建)时:
# dotnet --info
Host (useful for support):
Version: 2.1.8
Commit: 209f8aa25c
.NET Core SDKs installed:
No SDKs were found.
.NET Core runtimes installed:
Microsoft.NETCore.App 2.1.8 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET Core runtimes or SDKs:
https://aka.ms/dotnet-download
所以看起来好像已经安装了2.1.8,但它却不能起到2.1.1的作用。
我尝试了两件事:
如何使它工作?
答案 0 :(得分:1)
我发现使用ASP时,您无法使用.net核心映像并添加asp库。
您需要获取.net core asp docker镜像。