Visual Studio 2017中的Docker ASP.NET CORE 2.1应用程序。该应用程序无法在调试模式下启动

时间:2018-12-13 19:40:46

标签: c# visual-studio docker asp.net-core visual-studio-2017

我一直在开发Web应用程序ASP.NET CORE 2.1,并愉快地在带有Docker的Visual Studio中运行它。到现在。

  

当我尝试开始调试时出乎意料的是它是构建部分,但是   完全跳过运行部分。所以现在我无法调试我的   带有Visual Studio 2017的Docker容器。

没有显示错误,似乎一切正常,除了该应用程序无法启动的事实。甚至不在“输出”选项卡的可用列表中调试输出。 容器似乎正在运行,但是由于某些原因,Visual Studio并未将其附加到Docker映像进行调试。

任何帮助将不胜感激。

重新启动Visual Studio或计算机,删除bin,obj,.vs,%userprofile%\ vsdbg和%userprofile%\ onecoremsvsmon没有任何区别。 这是我的环境:

  1. Windows10
  2. Microsoft Visual Studio Enterprise 2017版本15.9.4
  3. VisualStudio.15.Release / 15.9.4 + 28307.222
  4. ASP.NET核心剃刀语言服务15.8.31590
  5. 用于容器1.1的Microsoft Visual Studio工具
  6. Visual Studio容器工具1.0

Docker:

  1. 版本2.0.0.0-win81(29211)
  2. 内部版本:4271b9e
  3. 引擎:18.09.0
  4. 撰写:1.23.2
  5. 机器:0.16.0

容器似乎正在运行:

CONTAINER ID        IMAGE               COMMAND               CREATED             STATUS              PORTS                                                                 NAMES
22852e61b41a        dockertest          "tail -f /dev/null"   4 minutes ago       Up 4 minutes        0.0.0.0:50659->80/tcp, 0.0.0.0:44304->443/tcp                         priceless_pare

Dockerfile:

FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

FROM microsoft/dotnet:2.1-sdk AS build
WORKDIR /src
COPY ["Dockertest/Dockertest.csproj", "Dockertest/"]
RUN dotnet restore "Dockertest/Dockertest.csproj"
COPY . .
WORKDIR "/src/Dockertest"
RUN dotnet build "Dockertest.csproj" -c Release -o /app

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

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

VS构建输出:

Target ContainerPrepareForLaunch:
  Using "ResolveVsDbgPath" task from assembly "C:\Users\aaaa\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.0.2105168\build\..\tools\Microsoft.VisualStudio.Containers.Tools.Tasks.dll".
  Task "ResolveVsDbgPath"
  Done executing task "ResolveVsDbgPath".
  Task "ContainerError" skipped, due to false condition; ('$(TargetFrameworkIdentifier)' == '.NETCoreApp' And
                                 '@(_Dockerfile->AnyHaveMetadataValue('TargetOS', 'Linux'))' == 'true' And
                                 !Exists('$(ContainerVsDbgPath)\vsdbg')) was evaluated as ('.NETCoreApp' == '.NETCoreApp' And
                                 'true' == 'true' And
                                 !Exists('C:\Users\aaaa\vsdbg\vs2017u5\vsdbg')).
  Using "ResolveMsVsMonPath" task from assembly "C:\Users\aaaa\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.0.2105168\build\..\tools\Microsoft.VisualStudio.Containers.Tools.Tasks.dll".
  Task "ResolveMsVsMonPath"
  Done executing task "ResolveMsVsMonPath".
  Using "PrepareForLaunch" task from assembly "C:\Users\aaaa\.nuget\packages\microsoft.visualstudio.azure.containers.tools.targets\1.0.2105168\build\..\tools\Microsoft.VisualStudio.Containers.Tools.Tasks.dll".
  Task "PrepareForLaunch"
    docker build -f "C:\Projects\Dockertest\Dockerfile" -t dockertest  --label "com.microsoft.created-by=visual-studio" "C:\Projects"
    Sending build context to Docker daemon  3.007GB

    Step 1/18 : FROM microsoft/dotnet:2.1-aspnetcore-runtime AS base
     ---> 1fe6774e5e9e
    Step 2/18 : WORKDIR /app
     ---> Using cache
     ---> 930ee0770e2d
    Step 3/18 : EXPOSE 80
     ---> Using cache
     ---> 4f184a8a4bd4
    Step 4/18 : EXPOSE 443
     ---> Using cache
     ---> bdf7dc4e92fd
    Step 5/18 : FROM microsoft/dotnet:2.1-sdk AS build
     ---> 04868b49e01f
    Step 6/18 : WORKDIR /src
     ---> Using cache
     ---> c27b25a30aeb
    Step 7/18 : COPY ["Dockertest/Dockertest.csproj", "Dockertest/"]
     ---> Using cache
     ---> 009cbf61e5ae
    Step 8/18 : RUN dotnet restore "Dockertest/Dockertest.csproj"
     ---> Using cache
     ---> 9baf38b818c8
    Step 9/18 : COPY . .
     ---> ae210461c587
    Step 10/18 : WORKDIR "/src/Dockertest"
     ---> Running in 024c6719cbd3
    Removing intermediate container 024c6719cbd3
     ---> f398384b2049
    Step 11/18 : RUN dotnet build "Dockertest.csproj" -c Release -o /app
     ---> Running in cacc4471c224
    Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
    Copyright (C) Microsoft Corporation. All rights reserved.

      Restore completed in 57.06 ms for /src/Dockertest/Dockertest.csproj.
      Dockertest -> /app/Dockertest.dll
      Dockertest -> /app/Dockertest.Views.dll
    Build succeeded.
        0 Warning(s)
        0 Error(s)

    Time Elapsed 00:00:09.30
    Removing intermediate container cacc4471c224
     ---> 5854863d47c7
    Step 12/18 : FROM build AS publish
     ---> 5854863d47c7
    Step 13/18 : RUN dotnet publish "Dockertest.csproj" -c Release -o /app
     ---> Running in 69df3a178cd7
    Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
    Copyright (C) Microsoft Corporation. All rights reserved.

      Restore completed in 67.48 ms for /src/Dockertest/Dockertest.csproj.
      Dockertest -> /src/Dockertest/bin/Release/netcoreapp2.1/Dockertest.dll
      Dockertest -> /src/Dockertest/bin/Release/netcoreapp2.1/Dockertest.Views.dll
      Dockertest -> /app/
    Removing intermediate container 69df3a178cd7
    Step 14/18 : FROM base AS final
     ---> 766815671751
     ---> bdf7dc4e92fd
    Step 15/18 : WORKDIR /app
     ---> Using cache
     ---> 61f28b8a64fa
    Step 16/18 : COPY --from=publish /app .
     ---> 6b6711105d65
    Step 17/18 : ENTRYPOINT ["dotnet", "Dockertest.dll"]
     ---> Running in f3be0a8361ee
    Removing intermediate container f3be0a8361ee
     ---> 774100a76bc9
    Step 18/18 : LABEL com.microsoft.created-by=visual-studio
     ---> Running in 76d649057957
    Removing intermediate container 76d649057957
     ---> dbf49735c067
    Successfully built dbf49735c067
    Successfully tagged dockertest:latest
    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.
    docker rm -f ce37c3274e9a73fdfeb0b5cb48d451cf3fea687ee3b5c91388ecad1d1f695149
    ce37c3274e9a73fdfeb0b5cb48d451cf3fea687ee3b5c91388ecad1d1f695149
    docker run -dt -v "C:\Users\aaaa\vsdbg\vs2017u5:/remote_debugger:rw" -v "C:\Users\aaaa\AppData\Roaming\ASP.NET\Https:/root/.aspnet/https:ro" -v "C:\Users\aaaa\AppData\Roaming\Microsoft\UserSecrets:/root/.microsoft/usersecrets:ro" -e "ASPNETCORE_URLS=https://+:443;http://+:80" -e "ASPNETCORE_HTTPS_PORT=44304" -e "ASPNETCORE_ENVIRONMENT=Development" -p 50659:80 -p 44304:443 --entrypoint tail dockertest -f /dev/null
    22852e61b41ad164632588db2b4027ad59cc5e876956fb99c7e8eadcbcfcdd77
  Done executing task "PrepareForLaunch".
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target "_CheckForInvalidConfigurationAndPlatform" skipped. Previously built successfully.
Target ReportTypeScriptVersion:
  Using "FormatLocalizedString" task from assembly "C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.1\build\TypeScript.Tasks.dll".
  Task "FormatLocalizedString"
  Done executing task "FormatLocalizedString".
  Task "FormatLocalizedString" skipped, due to false condition; ('$(TypeScriptVersionCheckResult)' == 'Downgrade' OR '$(TypeScriptVersionCheckResult)' == 'Upgrade') was evaluated as ('NoneSpecified' == 'Downgrade' OR 'NoneSpecified' == 'Upgrade').
  Task "Warning" skipped, due to false condition; ('$(TypeScriptShowVersionWarning)' == 'true' AND '$(TypeScriptVersionCheckResult)' == 'NoneSpecified') was evaluated as ('' == 'true' AND 'NoneSpecified' == 'NoneSpecified').
  Task "Warning" skipped, due to false condition; ('$(TypeScriptShowVersionWarning)' == 'true' AND ('$(TypeScriptVersionCheckResult)' == 'Downgrade' OR '$(TypeScriptVersionCheckResult)' == 'Upgrade')) was evaluated as ('' == 'true' AND ('NoneSpecified' == 'Downgrade' OR 'NoneSpecified' == 'Upgrade')).
  Task "Warning" skipped, due to false condition; ('$(TypeScriptBuildMode)' == 'true' AND ($(TypeScriptToolsVersion.StartsWith('2.')) OR $(TypeScriptToolsVersion.StartsWith('1.')))) was evaluated as ('' == 'true' AND (False OR False)).
Target Build:
Target CleanupEmptyRefsFolder:
  Using "RemoveDir" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
  Task "RemoveDir"
    Directory "C:\Projects\Dockertest\bin\Release\netcoreapp2.1\refs" doesn't exist. Skipping.
  Done executing task "RemoveDir".
Target "ExecuteToolsTarget" skipped, due to false condition; ('@(ToolsTarget)' != '') was evaluated as ('' != '').
Target "_PackAsBuildAfterTarget" skipped, due to false condition; ('$(GeneratePackageOnBuild)' == 'true' AND '$(IsInnerBuild)' != 'true') was evaluated as ('false' == 'true' AND '' != 'true').
Target "DotNetPublish" skipped, due to false condition; ( '$(DeployOnBuild)' == 'true' ) was evaluated as ( '' == 'true' ).

Done building project "Dockertest.csproj".

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:04:53.13
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

编辑: 注意,VS在执行以下任务时“坐着”“太长”(在此步骤之前更快):

docker build -f "C:\Projects\Dockertest\Dockerfile" -t dockertest  --label "com.microsoft.created-by=visual-studio" "C:\Projects"

1 个答案:

答案 0 :(得分:1)

好,一切现在都在工作!我在一堆被拔掉的头发上跳来跳去,不是因为我现在完全没有毛,而是因为我已经把头发修好了!:)))

事不宜迟,以下是破冰的原因: 由于某些原因,Docker For Windows丢失了与项目所在的驱动器的“连接”(可能是因为缺少更好的文字或权限?)。这正是我为纠正这种情况所做的事情:

  1. 打开Docker For Window“设置”菜单
  2. 进入“共享驱动器”
  3. 项目所在的驱动器的未选中“共享”复选框(标记已在那里)
  4. 点击“应用”按钮
  5. 再次选中“共享”复选框,然后再次单击“应用”按钮。

在最后一步中,弹出两次登录框,告诉我Docker需要我的凭据才能访问驱动器。域名已使用我的登录名预先填充。我已经两次输入密码并单击“确定”按钮。然后,我启动了项目,瞧,我的Web应用程序的登录页面按预期显示在浏览器中。简单,但如此狡猾!:))

老实说,当我忙着拔头发时,我也清理了硬盘以释放一些空间。我已经向Wild发布了大约10 GB。 IDK,无论这是否对成功有所贡献,但我读过,有人也这样做了,这对Docker有利。