To create a prelaunch task in Visual Studio Code, follow these steps:
- Open the Command Palette (Ctrl+Shift+P on Windows or Shift+Command+P on Mac).
- Type “task” and select “Tasks: Configure Task Runner”. This will create a
tasks.json
file in your project. - In the
tasks.json
file, you can define a task that runs before launch by adding a property calledisBackground
and setting it totrue
. For example:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"type": "shell",
"command": "gulp build",
"isBackground": true,
"problemMatcher": []
}
]
}
- You can then bind this task to the
launch
command by adding apreLaunchTask
property to your launch configuration inlaunch.json
. For example:
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"preLaunchTask": "build",
"program": "${workspaceFolder}/index.js"
}
]
}
This will cause the task to run before the launch command every time you debug your program.
Categories: Developer Chat
Leave a Reply