简体   繁体   English

如何附加到 Visual Studio Code 中的特定进程

[英]How can I attach to a specific process in Visual Studio Code

When I debug my .net core project in VSC I'm asked for a process Id to attach to.当我在 VSC 中调试我的 .net 核心项目时,我被要求提供一个要附加到的进程 ID。 This shows a long list of running processes where I either type or scroll to find a specific process.这显示了一长串正在运行的进程,我可以在其中键入或滚动以查找特定进程。 How can I attach to a specific same process each time I want to debug?每次我想调试时如何附加到特定的相同进程?

In visual studio code your debug options can be changed in the launch.json file.在 Visual Studio 代码中,您可以在launch.json文件中更改调试选项。 You can get to this file quickly through debug.您可以通过调试快速访问该文件。 Simply click the cog icon to open the json file.只需单击齿轮图标即可打开 json 文件。

Here you will see configurations for your setup.在这里,您将看到您的设置的配置。

"configurations": [
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processId":"${command:pickProcess}"
    }
]

name refers to the option inside the debug dropdownlist. name是指调试下拉列表中的选项。

Find the configuration using processId and change this to processName使用processId查找配置并将其更改为processName

processName is the process name to attach to. processName是要附加到的进程名称。 If this is used, processId should not be used.如果使用它, processId不应使用processId

The process name will be the .exe of the process id you'd normally be selecting.进程名称将是您通常选择的进程 ID 的 .exe。 Once this change is made next time you debug on the option you will automatically attach to your specified process if it is running.下次调试该选项时进行此更改后,您将自动附加到指定的进程(如果它正在运行)。

"configurations": [
    {
        "name": ".NET Core Attach",
        "type": "coreclr",
        "request": "attach",
        "processName":"someProcess.exe"
    }
]

An alternative is:另一种选择是:

  1. First run you app with the command dotnet watch core首先使用命令dotnet watch core运行您的应用程序
  2. The you can run the debut on .NET Core Attach你可以在.NET Core Attach上运行首次亮相
  3. On the list search and select .dll the file with YourProjectName.dll在列表中搜索并选择带有YourProjectName.dll .dll 文件

I hope it helped.我希望它有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM