I just installed Visual Studio Code, total newbie here. I want to debug some C++ code that is for Arduino project, it's too difficult uploading code to the ESP all day for debugging.
I can't get printf commands to output anything from the debug console. If I run the .exe from the command line the printf works fine.
I tried some options in the settings.json file
"externalConsole": "true",
"console": "integratedTerminal",
I saved the file, restarted Studio, no change.
Related
In VS Code you can open an terminal in an specific shell.
Instead of just Powershell, i wanted to start up in the Visual Studio Developer Powershell session.
Open the settings of VS Code in json format
This is what I arrived at after some research and playing around with the startup argemunts to get it exactly as I want.
(PS: I left out other profiles for clarity!)
"terminal.integrated.profiles.windows": {
"Visual Studio Professional 2022 Powershell": {
"path": "pwsh.exe",
"args": [
"-noexit",
"-nologo",
"-c",
"&{$cur = gi .;Import-Module \"C:\\Program Files\\Microsoft Visual Studio\\2022\\Professional\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell c9012106;set-location $cur;}"
],
"icon": "terminal-powershell"
}
},
"terminal.integrated.defaultProfile.windows": "Visual Studio Professional 2022 Powershell",
'path' is short because pwsh.exe is located via $PATH environment variable
Note that I had to split the command flag and command text in separate arguments.
It doesn't work as one string, although in regular shell this works of course.
The most elaborate part is the lauching of the Visual Studio shell.
I took the information from the installed shortcut you get after installation of VS2022.
I added an small bit to make sure we stay on the current working folder too!
New to both VS Code and Visual Studio... When I run my C# program in Visual Studio, the command prompt opens and the program is run there. In VS Code however, the program is run in the integrated debug console.
Is there a way I can set VS Code to open up cmd prompt and run my program there, rather than the VS Code debug console?
Thanks.
Go to settings and search "Terminal: Explorer Kind". Then set it to external select external.
I use Visual Studio 2017 RC to open a CMake project and then I find the working directory is always the output directory.
Is there any way to set the working directory to somewhere other than the directory of output file?
(Because there is no .sln file, I cannot set the working directory in the old way)
Update
I am not calling programs from CMake scripts. I am running the target program in Visual Studio. And I want to change the working directory for the target program.
As of writing (2017-03-23), it is not possible to set working directory via CMakeLists.txt. Here are some workarounds:
Using launch.vs.json
According to this bug report, you can add the setting inside your Debug and Launch Settings (right click the relevant CMakeLists.txt). This opens the launch.vs.json file, where you can add the working directory using the currentDir variable. Here's an example:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"projectTarget": "path\\to\\target",
"name": "My Awesome Project",
"currentDir": "${workspaceRoot}/src"
}
]
}
If you want you can go ahead and check that file in; it probably sits in .vs/launch.vs.json.
See the Visual C++ Team blog post. It doesn't mention currentDir though.
The syntax appears to be very similar to that used by Visual Studio Code, although the keywords are all different - VSCode uses cwd instead of currentDir, for example.
Using CMake >= 3.8.0 with VS_DEBUGGER_WORKING_DIRECTORY
See also: Does CMake offer a method to set the working directory for a given build system to use when running/debugging the project?
VS_DEBUGGER_WORKING_DIRECTORY is a new CMake target property in version 3.8.0. Set it like this:
set_target_properties(
MyProject PROPERTIES
VS_DEBUGGER_WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}/bin")
You need to use the old method of standalone CMake, generate .sln/.vcxproj files, open solution with Visual Studio, because the version of CMake integrated with Visual Studio 2017 is 3.6. Which leads to...
Wait until Visual Studio ships with CMake >= 3.8.0
It's unknown when this will happen; the team are currently looking at updating to CMake 3.7 so it'll be a while longer. However when this happens chances are it will support the VS_DEBUGGER_WORKING_DIRECTORY property.
Using currentDir, for example:
{
"version": "0.2.1",
"defaults": {},
"configurations": [
{
"type": "default",
"project": "CMakeLists.txt",
"name": "testd.exe (Debug\\testd.exe)",
"currentDir": "${workspaceRoot}\\app_home",
"args": [
"${workspaceRoot}\\app_home"
]
}
]
}
The reason why VS_DEBUGGER_WORKING_DIRECTORY not working is:
When we use VisualStudio IDE to manager a project, it just a text editor.
For example a cmake project, the IDE just running cmake command by params in CMakeSettings.json
Then if we choose ninja, it will not generate the .sln and .vcproj files, just using build.ninja to drive build process.
If we choose Visual Studio 2019, it will generate a .sln file and some .vcproj file, but these file just a middle step of building. The current VS-IDE window will not load these file, just use command line to utilize the vcproj/sln file to build.
The VS_DEBUGGER_WORKING_DIRECTORY would saved into these middle-step .vcproj files, that invisible of current IDE windows. (Remember: The current IDE windows just a text editor of CMakeLists.txt)
In other words, it doesn't matter between using VS-IDE with cmake and makefile.
Note: We can see the build process in Output window.
Note:
Whether we choose Ninja or VisualStudio2019, the backend build tools are same, MSVC.
But how can we use VS-IDE property?
Just open the middle-step .sln and Visual Studio will automatically sync these two windows.
I am just starting out in Type Script, and am using the new Visual Studios Code IDE. I am currently facing an issue where I can either use the visual studios type script plug-in, and run the javascript files using node. However it won't build the js file automatically when the ts file is saved. So i uninstalled the plugin, and installed typescript according to this video:
https://egghead.io/lessons/typescript-typescript-up-and-running-in-seconds
Now I can have one ts file be built by using the --watch option, but how would I accomplish auto building multiple .ts files when I move on to more complex projects that will require it?
Also is this the best way to write TypeScript using Visual Studios Code as my IDE? Currently I'm not a huge fan of this set up because I have to have a terminal open to watch a single ts file (which can mean a bunch of windows are required to watch each file, and also a terminal open to run the program.
I'm not sure whether you use Visual Studio Code or Visual Studio 2013. I assume it's VS Code (if it's not, consider switching. VS Code is really good!).
Now I'll quote myself from another answer.
You can do this with Build commands:
Create a simple tsconfig.json with watch = true (this will instruct compiler to watch all compiled files):
{
"compilerOptions": {
"target": "ES5",
"out": "js/script.js",
"watch": true
}
}
Note that files array is omitted, by default all *.ts files in all subdirectories will be compiled.
Configure your task (Ctrl+Shift+P -> Configure Task Runner):
{
"version": "0.1.0",
"command": "tsc",
"showOutput": "silent",
"isShellCommand": true,
"problemMatcher": "$tsc"
}
Now press Ctrl+Shift+B to build the project. You will see compiler output in the output window (Ctrl+Shift+O).
See one of my projects for more info:
tsconfig.json, .settings/tasks.json.
I hav my execuatable produced by command line building.
I want to debug it in command line itself as like as gdb does in linux.
Also i want run my program in Visual studio GUI from command line options..
How can i do that?
Make sure it is compiled in the debug version. Run the program. Then "Attach to Process" from VS tools menu.
You can also specify the runtime options when running the debugger (it's in the project properties).
I don't think that VS has a pure command line mode, but you could use CDB/NTSD.
http://msdn.microsoft.com/en-us/library/cc266320.aspx
It is what lots of developers at MS do.