g18*_*18c 8 .net c# docker .net-core
我在最新的 Windows 版本 Windows 10 2004 上使用 Linux 容器并启用 WSL 2 和 Docker Desktop 2.3.0.3 (45519)。
我右键单击 docker-compose 文件,然后选择Set as Startup Project.
然后我按 F5 进行调试。
我可以看到正在运行的图像,docker ps但是没有命中断点。
我无法查看日志(在 Visual Studio Containers 窗口中),因为它说:
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
Run Code Online (Sandbox Code Playgroud)
我已经从上面给出的链接安装了 SDK。
构建输出如下:
1>------ Build started: Project: Libertas.Host.Tickers.ScheduledTasks, Configuration: Debug Any CPU ------
1>Libertas.Host.Tickers.ScheduledTasks -> C:\Users\User\Source\Repos\myrepo\Libertas\src\Libertas.Host.Tickers.ScheduledTasks\bin\Debug\netcoreapp3.1\Libertas.Host.Tickers.ScheduledTasks.dll
1>docker build -f "C:\Users\User\Source\Repos\myrepo\Libertas\src\Libertas.Host.Tickers.ScheduledTasks\Dockerfile" --force-rm -t libertashosttickersscheduledtasks:dev --target base --label "com.microsoft.created-by=visual-studio" --label "com.microsoft.visual-studio.project-name=Libertas.Host.Tickers.ScheduledTasks" "C:\Users\User\Source\Repos\myrepo\Libertas\src"
1>Sending build context to Docker daemon 1.362MB
1>
1>Step 1/4 : FROM mcr.microsoft.com/dotnet/core/runtime:3.1-buster-slim AS base
1> ---> 86a2e7d45948
1>Step 2/4 : WORKDIR /app
1> ---> Running in d1ed1740d43e
1>Removing intermediate container d1ed1740d43e
1> ---> 90bd1703e28d
1>Step 3/4 : LABEL com.microsoft.created-by=visual-studio
1> ---> Running in 2626d5865d89
1>Removing intermediate container 2626d5865d89
1> ---> da74703374d2
1>Step 4/4 : LABEL com.microsoft.visual-studio.project-name=Libertas.Host.Tickers.ScheduledTasks
1> ---> Running in 7a381e7ea47a
1>Removing intermediate container 7a381e7ea47a
1> ---> fd2dd439cce6
1>Successfully built fd2dd439cce6
1>Successfully tagged libertashosttickersscheduledtasks:dev
1>SECURITY WARNING: You are building a Docker image from Windows against a non-Windows Docker host. All files and directories added to build context will have '-rwxr-xr-x' permissions. It is recommended to double check and reset permissions for sensitive files and directories.
1>docker rm -f 9ff95181e06801ed3d4b4d5743397604b743d77c840f2047fb2caee046e5d8eb
1>Error: No such container: 9ff95181e06801ed3d4b4d5743397604b743d77c840f2047fb2caee046e5d8eb
1>docker run -dt -v "C:\Users\User\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\Users\User\Source\Repos\myrepo\Libertas\src\Libertas.Host.Tickers.ScheduledTasks:/app" -v "C:\Users\User\Source\Repos\myrepo\Libertas\src:/src/" -v "C:\Users\User\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -v "C:\Users\User\.nuget\packages\:/root/.nuget/fallbackpackages" -e "DOTNET_USE_POLLING_FILE_WATCHER=1" -e "NUGET_PACKAGES=/root/.nuget/fallbackpackages" -e "NUGET_FALLBACK_PACKAGES=/root/.nuget/fallbackpackages" --name Libertas.Host.Tickers.ScheduledTasks_1 --entrypoint tail libertashosttickersscheduledtasks:dev -f /dev/null
1>ba95df9d32d6a0af07b1eab32af606131e075b2afff664c4003dbe3eae349543
========== Build: 1 succeeded, 0 failed, 6 up-to-date, 0 skipped ==========
Run Code Online (Sandbox Code Playgroud)
我的 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 ["Libertas.Host.Tickers.ScheduledTasks/Libertas.Host.Tickers.ScheduledTasks.csproj", "Libertas.Host.Tickers.ScheduledTasks/"]
COPY ["Libertas.Application.Tickers.ScheduledTasks/Libertas.Application.Tickers.ScheduledTasks.csproj", "Libertas.Application.Tickers.ScheduledTasks/"]
COPY ["PolygonIo.WebSocket/PolygonIo.WebSocket.csproj", "PolygonIo.WebSocket/"]
RUN dotnet restore "Libertas.Host.Tickers.ScheduledTasks/Libertas.Host.Tickers.ScheduledTasks.csproj"
COPY . .
WORKDIR "/src/Libertas.Host.Tickers.ScheduledTasks"
RUN dotnet build "Libertas.Host.Tickers.ScheduledTasks.csproj" -c Release -o /app/build
FROM build AS publish
RUN dotnet publish "Libertas.Host.Tickers.ScheduledTasks.csproj" -c Release -o /app/publish
FROM base AS final
WORKDIR /app
COPY --from=publish /app/publish .
ENTRYPOINT ["dotnet", "Libertas.Host.Tickers.ScheduledTasks.dll"]
Run Code Online (Sandbox Code Playgroud)
我无法点击任何断点,甚至无法确认应用程序是否正在运行。我有一个通用主机应用程序,我什至没有在public static void Main(string[] args).
指针非常感谢。
更新和修复
所以这是确凿的证据,特别是因为这是一个控制台应用程序,而不是一个 AspNetCore 应用程序。
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
Run Code Online (Sandbox Code Playgroud)
我发现我引用的库之一引用了Grpc.AspNetCore.
一旦我将这段代码移出,它就能够运行(我可以在容器实例未运行之前确认),并进行全面调试。
它编译好,容器运行,容器内的应用程序似乎从未启动。
问题我想找出原因,因为我不完全理解这是如何修复所有内容以及将来可以采取什么措施来避免的(似乎任何引用意外或以其他方式引用 AspNetCore 依赖项的库的控制台应用程序都可以有同样的问题)。
\n\n问题我想弄清楚为什么,因为我不完全理解这是如何解决所有问题以及将来可以采取哪些措施来避免(似乎任何引用意外或以其他方式引用 AspNetCore 依赖项的库的控制台应用程序)可能有同样的问题)。
\n
在 Visual Studio 解决方案资源管理器中向我们展示了包含 Nuget 包的依赖关系树以及上面列出的框架Microsoft.NETCore.App:
\n\n这是我们可以看到GitHub Repo引用 AspNetCore 的方式:
\n<FrameworkReference Include="Microsoft.AspNetCore.App" />\nRun Code Online (Sandbox Code Playgroud)\n我怎样才能阻止这种情况发生?
\n如果您正在寻找经典故事,就在这里。
\nIria 讨论的问题可以通过 NuGet 版本范围和通配符表示法来避免。在引用包依赖项时,NuGet 支持使用区间表示法来指定版本范围,总结如下:
\n+-----------+---------------+-------------------------------------------------------+\n| Notation | Applied rule | Description |\n+-----------+---------------+-------------------------------------------------------+\n| 1.0 | x \xe2\x89\xa5 1.0 | Minimum version, inclusive |\n| (1.0,) | x > 1.0 | Minimum version, exclusive |\n| [1.0] | x == 1.0 | Exact version match |\n| (,1.0] | x \xe2\x89\xa4 1.0 | Maximum version, inclusive |\n| (,1.0) | x < 1.0 | Maximum version, exclusive |\n| [1.0,2.0] | 1.0 \xe2\x89\xa4 x \xe2\x89\xa4 2.0 | Exact range, inclusive |\n| (1.0,2.0) | 1.0 < x < 2.0 | Exact range, exclusive |\n| [1.0,2.0) | 1.0 \xe2\x89\xa4 x < 2.0 | Mixed inclusive minimum and exclusive maximum version |\n| (1.0) | invalid | invalid |\n+-----------+-------------\nRun Code Online (Sandbox Code Playgroud)\n当您添加包强制执行版本时,您可以通过这种方式跟踪不同版本(以及最终的 .net 框架版本)的依赖关系。
\n| 归档时间: |
|
| 查看次数: |
390 次 |
| 最近记录: |