Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
以编程方式将调试器附加到Docker容器中运行的进程 问题:_Docker_Remote Debugging_Visual Studio Debugging - Fatal编程技术网

以编程方式将调试器附加到Docker容器中运行的进程 问题:

以编程方式将调试器附加到Docker容器中运行的进程 问题:,docker,remote-debugging,visual-studio-debugging,Docker,Remote Debugging,Visual Studio Debugging,如何以编程方式附加到本地计算机上Docker容器中运行的.NET核心进程 具体来说,我有一个集成测试,它运行一组Docker容器。我想将调试器附加到其中一个容器中的进程。我知道容器和流程,所以我所要寻找的只是一种以编程方式实际附加调试器的机制,以便在调试集成测试时,可以直接调试到应用程序中 背景 在VisualStudio2019中,可以将调试器附加到Docker容器中运行的进程 启动容器时,将包含vsdbg(例如,%USERPROFILE%\vsdbg\vs2017u5)的附加卷装载为/rem

如何以编程方式附加到本地计算机上Docker容器中运行的.NET核心进程

具体来说,我有一个集成测试,它运行一组Docker容器。我想将调试器附加到其中一个容器中的进程。我知道容器和流程,所以我所要寻找的只是一种以编程方式实际附加调试器的机制,以便在调试集成测试时,可以直接调试到应用程序中

背景 在VisualStudio2019中,可以将调试器附加到Docker容器中运行的进程

启动容器时,将包含
vsdbg
(例如,
%USERPROFILE%\vsdbg\vs2017u5
)的附加卷装载为
/remote\u debugger

docker run -v "$($env:USERPROFILE)\vsdbg\vs2017u5:/remote_debugger:rw"
然后,您可以使用
Debug->attach to Process…
附加调试器:

可能的选择
我怀疑我可以使用,但我希望有一个更简单的机制,因为基于EnvDTE的解决方案通常是维护上的难题。

您可以使用的组合来设置将支持的
launch.json

您需要使用EnvDTE调用
DebugAdapterHost.Launch
命令,因为您可能不需要用户干预。演示如何在Visual Studio中获取CommandWindow,以便可以发送命令

这些步骤是: 1.创建一个
launch.json
文件,如下所示:

{
  // NOTE: replace 'my_container_name' with the name of the container you want to connect to
  "version": "0.2.0",
  "adapter": "docker.exe",
  "adapterArgs": "exec -i my_container_name /remote_debugger/vsdbg --interpreter=vscode",
  "configurations": [
    {
      "name": ".NET Core Docker Attach",
      "type": "coreclr",
      "request": "attach",
      // replace with the process id you want to attach to. You can find this by running 'pidof' in the container
      // ex: `docker exec -it my_container_name pidof dotnet`
      "processId": 93
    }
  ]
}
  • 使用此命令调用您的
    launch.json
    文件:

    DebugAdapterHost.Launch/LaunchJson:“/EngineGuid:541B8A8A-6081-4506-9F0A-1CE771DEBC04

  • 从DTE获取命令窗口(快速脏代码示例):


  • 进一步的研究使我相信,是显示UI的组件-我希望我能以编程方式使用它。不熟悉该主题,但我正在尝试让有经验的人参与其中,可能会有所帮助:)嗨,RB,根据Pierson的回答,在这个过程中,您可能必须使用EnvDTE,你可以考虑把它标记为答案,如果它解决了你的问题。谢谢皮尔森!
    DTE dte = (DTE)Package.GetGlobalService(typeof(SDTE));
    Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindCommandWindow);
    window.Activate();
    
    CommandWindow commandWindow = window.Object as CommandWindow;
    
    string command = "DebugAdapterHost.Launch " + 
                     "/LaunchJson:\"path/to/launch.json\" " + 
                     "/EngineGuid:541B8A8A-6081-4506-9F0A-1CE771DEBC04";
    
    commandWindow.SendInput(command, true);