Once I had set launch.json and I ran gdb and debugged in my code successfully until something happened and all breakpoint became "gray" with the such message:
"Module containing this breakpoint has not yet loaded or the breakpoint address could not be obtained."
However, debugger attaches to running program and I even can make steps from main, but still breakpoint are not hit... This is C++ project that is built with cmake with gcc with -DCMAKE_BUILD_TYPE=DEBUG flag.
launch.json is this:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "./MyProject/project",
"args": [],
"stopAtEntry": false,
"cwd": "/home/AA/workspace",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerServerAddress": "/*Cannot write here, but it's fine*/",
"sourceFileMap": {/*Cannot write here, but it*/}
},
]
}
How do I fix this problem?
I was looking for an answer in other resources and the most solutions say that you should -g option if you compiler a project with gcc. It wasn't my case because I use cmake but I had one detail that I debugged code that was run in docker.
When you work with files in VS code from your user and docker runs project from another user, you should add the option "sourceFileMap": {} in launch.json:
"sourceFileMap": {
"/home/user/project/file.hpp" : "/home/YourNameBeyondDocker/project/file.hpp",
...
I added wrong path in this option. When I took it out, my debugger finally started hitting breakpoints!
On my linux VM I have set up a docker container to build and debug my vs code C++ project via an ssh connection. Building works inside the container as well as running and debugging with breakpoints. I am stuck on how to redirect stdout to the Output and Problems tabs so i can see warnings generated from the build and then navigate to the affected files. Instead it just outputs the build to a terminal window.
The project is located in a docker volume in the location:
/var/snap/docker/common/var-lib-docker/volumes/vol-tom-2/_data/My-Project
And inside the container it is located in:
/home/buildmaster/workspace/My-Project
For debugging i have modified the launch.json file so that when setting breakpoints it matches up the files in the project to the ones in the container, by adding this line:
"sourceFileMap": {
"/home/user/workspace": "/var/snap/docker/common/var-lib-docker/volumes/vol-tom-2/_data/"
},
I would like to find something similar in tasks.json so that it can sync up my local vs code project with the warnings and errors generated from the build inside the container.
Below is my tasks.json file, thanks in advance if any one has any idea how to solve this!
{
"version": "2.0.0",
"command": "/bin/sh",
"args": ["-c"],
"reveal": "always",
"tasks": [
{
"args": [
"user#localhost",
"-p",
"32772",
"/home/build-scripts/build-script.sh"
],
"label": "build",
"command": "ssh",
"problemMatcher": {
"owner": "cpp",
"fileLocation": ["relative", "${workspaceRoot}"],
"pattern": {
"regexp": "^\/host\/(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
"file": 1,
"line": 2,
"column": 3,
"severity": 4,
"message": 5
}
},
}
]
}
VSCode Version: 1.12.2
OS Version: Windows 10
Electron Version: 1.7
Steps to Reproduce:
I did an NPM update for electron, and a few other modules, and the Debug Launch of Electron stopped working. However, I can still manually start Electron from the command prompt, and it seems that the same command is what VSCODE is doing.
I.e. this works:
> d:\wwwroot\librarian2017\dashboard/node_modules/.bin/electron.cmd --debug-brk=24964 --nolazy main.js
But I get the message (below) when I run launch.json, and the blue status bar at the bottom of the VSCODE window turns orange for a second and then goes back to blue. No indication of what crashed. But nothing pops up.
Debugging with legacy protocol because a runtime executable is set.
d:\wwwroot\librarian2017\dashboard/node_modules/.bin/electron.cmd --debug-brk=24964 --nolazy main.js
Launch.json
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "DashBoard",
"program": "${workspaceRoot}/main.js",
"stopOnEntry": false,
"args": [],
"cwd": "${workspaceRoot}",
"runtimeExecutable": "${workspaceRoot}/node_modules/.bin/electron.cmd",
"env": {},
"sourceMaps": true
}
Probably a bug in VSCODE. I rolled electron back to 1.6.7 and it works again. I filed an issue on github.
I am looking forward to run asp.net mvc apps in vscode but it seems that the only pages that I found on google is with asp.net core which is not what I am looking. Can someone guide me with some steps, I installed some plugins like c# and msbuild. After attempt to run it. it display the following error:
"Failed to launch external program msbuild . spawn msbuild ENOENT"
The error Failed to launch external program msbuild . spawn msbuild ENOENT happens because vscode\task runner cannot find msbuild.
To run asp.net mvc 4.5 in visual studio code editor, you will need to install msbuild tools (I have installed the 2017 version) and IIS Express.
You could use vswhere to check msbuild location, in my case is C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\msbuild.exe
In vscode execute the command Tasks: Configure Task Runner and edit the content of tasks.json according the file.
{
"version": "0.1.0",
"taskSelector": "/t:",
"showOutput": "silent",
"tasks": [
{
"taskName": "build",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"windows": {
// change according your msbuild location
"command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\msbuild.exe"
},
// Show the output window only if unrecognized errors occur.
"showOutput": "silent",
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
},
{
"suppressTaskName": true,
"taskName": "iisexpress",
"isShellCommand": true,
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args": [
// change according your project folder and desired port
"/path:${workspaceRoot}\\MyProjectFolder",
"/port:51714"
],
// Show the iisexpress output always.
"showOutput": "always"
}
]
}
You don't need to restart your IIS on every change, you just need to build the application CTRL+SHIFT+B.
If you wan't to stop IIS use the vscode command Tasks: Terminate Running Task.
References:
https://stackoverflow.com/a/42719644/5270073
https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-from-the-command-line
I've created a gulpfile that handle the build for me:
It starts an IISExpress instance.
Refresh my browser on razor code change.
And automatically rebuild my application when I change C# code.
You can find the gulpfile on my project's Github
As per VS Code documentation, VS Code does not support debugging applications running on the Desktop .NET Framework. The ASP.NET MVC Application (though ASP.NET Core is supported) are not recognized by VS Code. Hence VS Code is lightweight tool to edit a file, they are recommending to use Visual Studio Community.
For Visual Studio Code 1.30.2 I've got it configured to build and run my ASP.NET applications in IISExpress using the following setup.
Terminal -> Configure Tasks
Then select Create tasks.json file from template entry.
Once you do that then select the MSBuild template
This will create the default MS build task template.
You should be able to copy the following to the task.json file:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
//Task for building your ASP.NET Solution
{
"label": "build",
"type": "shell",
"command": "msbuild",
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true",
"/t:build"
],
"windows": {
"command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\msbuild.exe"
},
"group": "build",
"presentation": {
// Reveal the output only if unrecognized errors occur.
"reveal": "always"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
},
//Task for running App in IIS Express
//You can add additional projects here if you want to run more than one project in IIS Express
//For example this shows how I'm running my WebApp and API locally in IIS Expresse
{
"label": "iisexpress-WebApp",
"type": "shell",
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args":[
"/path:${workspaceRoot}\\Web",
"/port:52945"
],
"presentation": {
"reveal": "always"
}
},
{
"label": "iisexpress-API",
"type": "shell",
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args":[
"/path:${workspaceRoot}\\Api",
"/port:49243"
],
"presentation": {
"reveal": "always"
}
}
]
}
Once you save the file just hit Ctrl + Shift + B and select the Build task from the window. If all goes well you should see the output displayed in the terminal below.
Then to spin up your Apps in IIS go to Terminal -> Run Task
That window will then show your IIS Express tasks, select the one you want to spin up and you should see the Output window show IIS starting up. Once that is successful just open your browser and navigate to localhost:{portyouconfigured} and you should see your application running.
I know I'm a little late, but after researching this myself in 2019, I think using VSCode's tasks is a better approach.
Create a tasks.json file inside your project's .vscode folder, this is where the below code will live.
Add the following script to tasks.json, I'm using this to build the project and then run iisexpress.
Once saved, you can run the Build & Run Server task by pressing pressing CTRL+SHIFT+B. You can also just access the available commands with CTRL+SHIFT+P and search for task: run build task.
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build & Run Server",
"dependsOrder": "sequence",
"group": "build",
"dependsOn":["Build ASP.NET", "Run IIS EXPRESS"]
},
{
"type": "shell",
"label": "Build ASP.NET",
"group": "build",
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": true
},
"args": [
// Ask msbuild to generate full paths for file names.
"/property:GenerateFullPaths=true"
],
"windows": {
// change according your msbuild location
"command":"${env:ProgramFiles(x86)}\\Microsoft Visual Studio\\2019\\Enterprise\\MSBuild\\Current\\Bin\\msbuild.exe"
},
// Use the standard MS compiler pattern to detect errors, warnings and infos
"problemMatcher": "$msCompile"
},
{
"type":"shell",
"label": "Run IIS EXPRESS",
"group": "build",
"windows": {
"command": "C:\\Program Files (x86)\\IIS Express\\iisexpress.exe"
},
"args": [
// change according your project folder and desired port
"/path:${workspaceRoot}\\VSSMVCProj",
"/port:59010"
],
// Show the iisexpress output always.
"presentation": {
"echo": true,
"reveal": "always",
"focus": false,
"panel": "shared",
"showReuseMessage": true,
"clear": false
},
}
],
}
Since Visual Studio Code 1.14
There is a new syntax to create tasks.
In your Menu Click on
Terminal -> Configure Tasks
Create a task in vscode that build your project like so:
{
"version": "2.0.0",
"tasks": [
{
"label": "build",
"args": [
"${workspaceRoot}\\Some\\Window\\Path\\ToSolution.sln",
"/target:Build"
],
// Path to your msbuild
// The path used corresponds to the path provided by a Visual Studio 2017 installation.
// To find it your msbuild path, go in your file explorer, and search for "msbuild.exe".
"windows": {
"command": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Professional\\MSBuild\\15.0\\Bin\\msbuild.exe"
},
"problemMatcher": "$msCompile"
}
]
}
The path used corresponds to the path provided by a Visual Studio 2017 installation.
To find it your msbuild path, go in your file explorer, and search for "msbuild.exe".
I would better recommend you installing dotnet cli to get started on it within 10 minutes as page says. If you're using Linux as I was using CentOS and followed the steps below in terminal:
sudo rpm -Uvh https://packages.microsoft.com/config/rhel/7/packages-microsoft-prod.rpm
sudo yum update
sudo yum install dotnet-sdk-2.2
To confirm if dotnet-cli installed successfully:
dotnet
The commmand below sets up a basic asp.net web application in myWebApp folder:
dotnet new webApp -o myWebApp --no-https
cd myWebApp
Simply type dotnet run in terminal to run your first asp.net app This makes your first project run sucessfully. In my opinion, this would work better with Visual studio code than any other method. I use this link source
I have an Electron app that I was able to debug in Visual Studio Code. After I upgraded to version 0.10.8 it will no longer run.
I am getting the error message below in my launch.json file:
Relative paths will no longer be automatically converted to absolute ones. Consider using ${workspaceRoot} as a prefix.
Absolute path to the runtime executable to be used. Default is the runtime executable on the PATH.
Here is my launch.json file:
{
"version": "0.2.0",
"configurations": [
{
"name": "My First Electron App",
"type": "node",
"request": "launch",
"program": "$(workspaceRoot}/app/main.js", //ERROR
"stopOnEntry": false,
"args": [],
"cwd": "$(workspaceRoot}",
"runtimeExecutable": "$(workspaceRoot}/node_modules/electron-prebuilt/dist/electron.app/Contents/MacOS/Electron", //ERROR
"runtimeArgs": [
"--nolazy"
],
"env": {
"NODE_ENV": "development"
},
"externalConsole": false,
"sourceMaps": false,
"outDir": null
},
{
"name": "Attach",
"type": "node",
"request": "attach",
"port": 5858
}
]
}
I am getting the green squiggly line mentioned for the two lines with //ERROR at the end.
I saw this article, but honestly was familiar with VS Code enough to understand how this should be implemented: https://code.visualstudio.com/Docs/editor/tasks#_variable-substitution
UPDATE
I replaced the value for "cwd" with "${workspaceRoot}" as recommended by Isidor. The green squiggly line went away.
I updated the error message that I am still seeing on the other two lines.
When I hit F5 I get this error message:
request 'launch': runtime executable '/private/var/git/electron-vs-code/$(workspaceRoot}/node_modules/electron-prebuilt/dist/electron.app/Contents/MacOS/Electron' does not exist
There is a typo in your json. Change the parenthesis after the $ in $(workspaceRoot} to a curly brace. This should at least fix the warning.
Even though you are getting the relative path warning VSCode still automatically converts relative to absolute paths in 0.10.8. To get rid of the warnings for "cwd", instead of "." please put "${workspaceRoot}".
What happens when you run try to debug your electron app, do you see some other error, since the relative to absolute can not be the true cause of this. If you command palette / open developper tools -> do you see some error in the console?