【发布时间】:2020-11-23 19:25:47
【问题描述】:
我正在使用 Visual Studio 2019(已启用 Docker 支持)编写一个 .Net Core 3.1 Worker Service 应用程序。
如果我使用 Docker 启动应用程序一切正常,但是当我向项目添加 Serilog.AspNetCore 3.4.0 依赖项时,我无法再使用 docker 进行调试了。
案例:
- 在没有 Serilog 的情况下在本地启动应用程序 --> 确定
- 在没有 Serilog 的情况下在 Docker 上启动应用程序 --> 确定
- 使用 Serilog 在本地启动应用程序 --> 确定
- 使用 Serilog 在 Docker 上启动应用程序 --> 错误
Visual Studio 返回的错误是:
这是控制台返回的错误:
-------------------------------------------------------------------
You may only use the Microsoft .NET Core Debugger (vsdbg) with
Visual Studio Code, Visual Studio or Visual Studio for Mac software
to help you develop and test your applications.
-------------------------------------------------------------------
It was not possible to find any compatible framework version
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found.
- No frameworks were found.
You can resolve the problem by installing the specified framework and/or SDK.
The specified framework can be found at:
- https://aka.ms/dotnet-core-applaunch?framework=Microsoft.AspNetCore.App&framework_version=3.1.0&arch=x64&rid=debian.10-x64
The program 'dotnet' has exited with code 150 (0x96).
编辑:
这是VS 2019自动生成的Dockerfile:
#See https://aka.ms/containerfastmode to understand how Visual Studio uses this Dockerfile to build your images for faster debugging.
FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
WORKDIR /app
FROM mcr.microsoft.com/dotnet/core/sdk:3.1-buster AS build
WORKDIR /src
COPY ["MensaNotificationService/MensaNotificationService.csproj", "MensaNotificationService/"]
RUN dotnet restore "MensaNotificationService/MensaNotificationService.csproj"
COPY . .
WORKDIR "/src/MensaNotificationService"
RUN dotnet build "MensaNotificationService.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "MensaNotificationService.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "MensaNotificationService.dll"]
问题是什么,我该如何解决?
【问题讨论】:
-
您是否尝试阅读错误消息?
The framework 'Microsoft.AspNetCore.App', version '3.1.0' was not found. -
这是一个毫无意义的错误,因为它安装在我的 PC/Linux 容器上,我可以在不使用 Serilog 的情况下毫无问题地执行应用程序(在 Windows 或 Linux 容器上)。你试过读我的问题吗?
-
请分享
Dockerfile -
@Ziaullah Kha 我已经添加了它。它是标准的 VS 生成的
-
@E.Benedos 你创建了一个工作服务,而不是一个网络应用程序。项目和 docker 文件都不包含 ASP.NET Core。该错误清楚地说明缺少 ASP.NET Core。你想做什么?你真的想创建一个网络应用程序吗?还是你添加了错误的 Serilog 包?
标签: docker serilog .net-core-3.1 microsoft.extensions.hosting