vscode 调试:在附加之前启动程序

vscode debugging: launch program prior to attaching to it

我正在为一些 C# 程序开发插件。为了调试我的插件,我需要

  1. 启动程序,
  2. 将调试器附加到程序。

我该怎么做 1.?

我的 launch.json 看起来像这样:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "net48",
            "type": "clr",
            "request": "attach",
            "processName":"sldworks.exe",
        }
    ]
}

当我开始调试时,我收到(预期的)消息,指出没有找到具有指定名称的进程。

所以我尝试添加

"preLaunchTask": "C:\myPath\sldworks.exe"

进入configuration,但随后VScode说

Could not find the task 'C:\myPath\sldworks.exe'.

我仔细检查了路径是否正确,如果我将其复制到 cmd 并按下 ENTER,程序就会启动。

在@DavidG 的提示下,我能够弄明白。我在命令中遇到了一些空格问题,但也能够解决这个问题。

launch.json:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "net48",
            "type": "clr",
            "request": "attach",
            "processName":"sldworks.exe",
            "preLaunchTask": "runSwx"
        }
    ]
}

tasks.json:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "runSwx",
            "type": "shell",
            "command": "C:/'Program Files'/'SOLIDWORKS Corp'/SOLIDWORKS/sldworks.exe"
        }
    ]
}