I am using vscode to debug a typescript program. Below is the configuration. It has a preLaunchTask to use the task to build the code before debugging. when I run debugger, it prompts an error dialog Could not find the task 'build'. It fails to find the build task which is already defined in tasks section. How can I make it work in vscode?
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/node/src/index.ts",
"skipFiles": [
"<node_internals>/**"
],
"preLaunchTask": "build",
"outFiles": [
"${workspaceFolder}/node/dist/**/*.js"
]
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
],
"tasks": [
{
"label": "build",
"type": "npm",
"script": "yarn build"
}
]
}
The custom tasks should be in a separate tasks.json file, not in the same launch.json file.
From the docs on launch.json attributes:
preLaunchTask - to launch a task before the start of a debug
session, set this attribute to the name of a task specified in
tasks.json (in the workspace's .vscode folder).
See the VS Code tutorial on creating Tasks Auto-Detection and Custom Tasks.
Related
I am using VS Code and I try to debug an executable with cygwin gdb compiled with cygwin gcc.
The problem is that it searches for the files within the build folder:
C:\XXX\build\gcc\C\XXX\test\source\test_source.cpp
Of course it cannot find it there, because the sources are not in the build folder, but one folder above.
This is the launch.json I use:
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}\\build\\gcc\\XXX\\test\\XXX.exe",
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"MIMode": "gdb",
"miDebuggerPath": "C:\\Program Files\\T_cygwin\\bin\\gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
This all happens on Windows. I tried out using mingw64 directly where this problem does not occur. So I assume it has to do something with Unix paths. Is there a way to find the right debug files?
I am trying to launch swagger UI in browser using dotnet run command. Here is what I have tried in launch.json file. Expected outcome is that it should launch browser at the specified url and open swagger UI automatically. FYI I am using dotnet5 and created new web api project that already has swagger baked in. It doesn't launch the browser.
If you are using dotnet run command then its a known limitation that it doesn't launch a browser.
Please refer to this link for confirmation
While it doesn't launch it, it will still have your project running just means you manually have to type it in browser or use one of the workarounds listed in that issue.
Use compounds launch settings
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/src/WebApi/bin/Debug/net7.0/YourWebDll.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
},
{
"name": "Launch Chrome",
"request": "launch",
"type": "chrome",
"url": "https://localhost:5001/swagger/index.html",
"webRoot": "${workspaceFolder}"
}
],
"compounds": [
{
"name": ".Net Core & Chrome",
"configurations": [".NET Core Launch (console)","Launch Chrome"]
}
]
This will run your app and launch chrome at the URL you want.
I need to have vscode to launch vscode live server as a run configuration in launch.json, to be able to include its launch with other run configurations in a compound launch.
I have tried the "Launch Extension" of type "pwa-extensionHost" with several different arguments and runtimeexecutables, for example
{
"name": "Launch Extension",
"request": "launch",
"type": "pwa-extensionHost",
"runtimeExecutable": "liveserver"
}
and
{
"name": "Launch Extension",
"request": "launch",
"type": "pwa-extensionHost",
"args": [
"--extensionDevelopmentPath=${workspaceFolder}",
"liveserver"
]
}
but couldn't get it run.
I am playing with a few programming languages within Visual Studio Code. My initial language is Python, and then I added Go in there within their own respective folders. When I run the Go file, it tries to interpret with Python, which obviously would fail.
Could I have different languages within the same project and separate them by different interpreter?
How do I point one folder to run with Python, the other to run with Go?
Thanks.
I've gotten it to work. The Configuration settings control what you are building. It is set within the launch.json file, and you can have different languages with the same project and run them in different interpreter/compiler.
This is what I have in my launch.json.
"version": "0.2.0",
"configurations": [
{
"name": "GO: Launch",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${fileDirname}",
"env": {},
"args": []
},
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "integratedTerminal"
}
]
For example, my root workstation directory is /home/chain/Project. And I have two separate projects which is python and website. My launch.json goes:
{
"version": "0.2.0",
"configurations":
[
{
"name": "Python",
"type": "python",
"request": "launch",
"stopOnEntry": true,
"pythonPath": "${config:python.pythonPath}",
"program": "${workspaceRoot}/python_project_source/test.py",
"cwd": "${workspaceRoot}/python_project_source",
"env": {},
"envFile": "${workspaceRoot}/.env",
"debugOptions": [
"WaitOnAbnormalExit",
"WaitOnNormalExit",
"RedirectOutput"
]
},
{
"type": "chrome",
"request": "launch",
"name": "Launch Chrome against localhost",
"url": "${workspaceRoot}/website/test.html",
"webRoot": "${workspaceRoot}/website"
}
]
}
As expected when I select test.py and press 'F5' it can switch to python debug environment, and when I select test.html the Chrome will be opened.
The fact is, VS code only remember the environment I debugged last time rather than change it automatically. So the only thing I do now is adding some comments to one environment (/* */) when I need to compile the other.:(
Is there something wrong in my launch.json?
Automatically switching the debug environment based on the file (or file-type) is not a current feature of Visual Studio Code, I believe.
You'll have to manually switch the launch configuration depending on the type of debugging task you want to perform.
And, of course, you could consider writing a feature request: https://github.com/Microsoft/vscode