远程debugging.NET核心Linux Docker容器 – “当前源与内置到.dll中的版本不同”
- docker
- .NET Core 1.1
- Visual Studio 2017
- .NET核心debugging器(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."
我将一步一步地了解如何构build我的.NET核心Docker镜像,并从此镜像运行Container实例,然后使用Visual Studio 2017连接远程, 我的Dockerfile.debug位于我的问题的底部 :
- 在我的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
//在容器中运行并映射我的.NET Core Webapi在端口5000上将主机端口8080映射到主机上的端口10222,并将Container中的端口22映射到端口10222 -
docker exec -it tsl.api.security.container.debug bash
//terminal从主机运行容器 -
/usr/sbin/sshd
//启动sshd
好吧,现在容器已经准备好远程debugging了,在Visual Studio 2017的机器上使用ssh和Visual Studio 2017,
- 从git中取出最新的代码
- 用Visual Studio 2016打开.sln
- 内置debugging
- 转到工具 – >选项 – >跨平台和我的SSH远程:
- CTRL + ALT + P //附加到进程
- select连接types – > SSH
- select托pipe(.NET Core for Unix)
和中提琴! 我们有我的问题:
如果我们在Docker容器中查看/app
,我们可以看到pdbs:
而源代码是相同的,因为我的工作stream解释中的git pull步骤演示。
不知道从哪里去…
这是我的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 https://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 http://+:5000 EXPOSE 5000 22 ENTRYPOINT ["dotnet", "TSL.Security.Service.dll"]
Tools->Options->Debugging->General
,closures“要求源文件完全匹配原始版本”。 不理想,但至less它击中VS2017源代码中设置的断点。
一旦你发现如何正确解决这个问题,请让我知道。