远程调试.NET Core Linux Docker容器

编程入门 行业动态 更新时间:2024-10-24 00:30:15
本文介绍了远程调试.NET Core Linux Docker容器-“当前来源与.dll中内置的版本不同".的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述
  • Docker
  • .NET Core 1.1
  • Visual Studio 2017
  • .NET Core调试器(clrdbg)

我收到以下错误:

"The breakpoint will not currently be hit. A copy of TokenController.cs was found in TSL.Security.Service.dll, but the current source code is different from the version built into the TSL.Security.Service.dll."

我将逐步构建.NET Core Docker映像并从该映像运行一个Container实例,然后将其与Visual Studio 2017远程连接,我的Dockerfile.debug在我的问题底部:

I will got step by step how I build my .NET Core Docker image and run a Container instance from this image, and then connect remote with Visual Studio 2017, my Dockerfile.debug is at the bottom of my question:

  • 在我的Docker主机上cd ~/repos/api.security//一个git存储库
  • git pull//从git中提取.NET Core项目的最新代码
  • dotnet restore
  • dotnet publish//没有其他参数与.pdbs一起发布
  • docker build -t tsl.api.security.image.debug -f Docker.debug .
  • docker run -d -p 8080:5000 -p 10222:22 --name=tsl.api.security.container.debug -t tsl.api.security.image.debug//在容器5000上的容器中运行我的.NET Core Webapi并将其映射到主机端口8080,并将容器22中的ssh映射到主机上的端口10222
  • docker exec -it tsl.api.security.container.debug bash//从主机终端进入正在运行的容器
  • /usr/sbin/sshd//启动sshd
  • on my docker host cd ~/repos/api.security //a git repository
  • git pull //pull latest code from git for .NET Core project
  • dotnet restore
  • dotnet publish //with no other args publishes with .pdbs
  • docker build -t tsl.api.security.image.debug -f Docker.debug .
  • docker run -d -p 8080:5000 -p 10222:22 --name=tsl.api.security.container.debug -t tsl.api.security.image.debug //run and map my .NET Core Webapi in Container on port 5000 to host port 8080 and map ssh in the Container, port 22, to port 10222 on the host
  • docker exec -it tsl.api.security.container.debug bash //terminal into running container from host
  • /usr/sbin/sshd //start sshd
  • 好吧,现在容器已准备好在Visual Studio 2017的机器上使用ssh和Visual Studio 2017进行远程调试:

    Ok great, now that container is ready for remoting debugging, using ssh with Visual Studio 2017, on my machine with Visual Studio 2017:

  • 从git中提取最新代码
  • 使用Visual Studio 2016打开.sln
  • 内置调试
  • 转到工具->选项->跨平台和我的SSH远程服务器:
  • CTRL + ALT + P//附加到进程
  • 选择连接类型-> SSH
  • 选择托管(适用于Unix的.NET Core)
  • pull latest code from git
  • open .sln with Visual Studio 2016
  • Build in Debug
  • Go to Tools -> Options -> Cross Platform and my SSH Remote:
  • CTRL + ALT + P //attach to process
  • Select Connection Type -> SSH
  • Select Managed (.NET Core for Unix)
  • 中提琴!我们有我的问题:

    And viola! We have my issue:

    如果我们在Docker容器中查看/app,我们会看到pdbs:

    If we look at /app in my Docker Container we can see pdbs:

    并且源代码是相同的,正如我的工作流说明中的git pull步骤所演示的.

    And the source code is the same, as the git pull steps in my workflow explanation demonstrates.

    不确定从这里要去哪里...

    Not sure where to go from here...

    这是我的Dockerfile.debug:

    Here is my Dockerfile.debug:

    # Use the standard Microsoft ASP.NET Core container FROM microsoft/aspnetcore # File Author / Maintainer MAINTAINER Brian Ogden WORKDIR / RUN apt-get update && apt-get install -y unzip RUN apt-get install -y openssh-server RUN mkdir /var/run/sshd RUN echo 'root:password' | chpasswd RUN sed -i 's/PermitRootLogin without-password/PermitRootLogin yes/' /etc/ssh/sshd_config RUN sed 's@session\s*required\s*pam_loginuid.so@session optional pam_loginuid.so@g' -i /etc/pam.d/sshd ENV NOTVISIBLE "in users profile" RUN echo "export VISIBLE=now" >> /etc/profile #install CLRDBG, Microsoft's new cross-platform command line debugger used for debugging code running on .NET Core RUN curl -sSL aka.ms/getclrdbgsh | bash /dev/stdin vs2015u2 ~/clrdbg # Copy our code from the "/src/MyWebApi/bin/Debug/netcoreapp1.1/publish" folder to the "/app" folder in our container WORKDIR /app COPY ./src/TSL.Security.Service/bin/Debug/netcoreapp1.1/publish . # Expose port 80 for the Web API traffic ENV ASPNETCORE_URLS +:5000 EXPOSE 5000 22 ENTRYPOINT ["dotnet", "TSL.Security.Service.dll"]

    推荐答案

    Tools->Options->Debugging->General,关闭要求源文件与原始版本完全匹配".这并不理想,但至少会达到VS2017中源代码中设置的断点.

    Tools->Options->Debugging->General, turn off "Require source files to exactly match the original version". Not ideal, but at least it hits the breakpoint set in the source code in VS2017.

    一旦您找到正确解决此问题的方法,请告诉我.

    Please let me know once you find out how to properly fix this.

    更多推荐

    远程调试.NET Core Linux Docker容器

    本文发布于:2023-11-15 02:57:56,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1590537.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:容器   Core   NET   Docker   Linux

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!