How to execute batch file before debugging with VS Code

被刻印的时光 ゝ 提交于 2020-01-04 01:19:40

问题


I'm developing with Typescript, nodeJS and VS Code.

Debugging with VS Code, I have configuration in my launch.json.

{
        "type": "node",
        "request": "launch",
        "name": "Launch via NPM",
        "runtimeExecutable": "npm",
        "runtimeArgs": [
            "run-script",
            "debug"
        ],
        "port": 9229
},

Is it possible to run a batch file before the service is started? With console I would normally run it with

env.cmd
npm start

回答1:


You should create a new task that you want to execute before debug with a specified "identifier" and it as a "preLaunchTask" into your launch.json (the task type can be also a "shell type" that will be executed as a shell command)

e.g.: my build:test task in launch.json:

 {
    "type": "npm",
    "script": "build:test",
    "identifier": "buildtest",
    "group": {
        "kind": "test",
        "isDefault": true
    }
}

and the related debug task:

{
    "type": "node",
    "request": "launch",
    "name": "Mocha Tests",
    "preLaunchTask": "buildtest",
    "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
    "args": [
        "-u",
        "tdd",
        "--timeout",
        "999999",
        "--colors",
        "${workspaceFolder}/temp/test/index.js"
    ],
    "internalConsoleOptions": "openOnSessionStart"
}


来源:https://stackoverflow.com/questions/49193079/how-to-execute-batch-file-before-debugging-with-vs-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!