VSCode PowerShell 0.11.0 Debug Console is no longer used - How do I "correctly" use VSCode now? - visual-studio-code

I am still a relatively new PowerShell coder, and I have been successfully using the PowerShell extension v0.8.0 for Visual Studio Code. I could write a script, press F5, and happily see my output.
Today I noticed there was an upgrade to v0.11.0, so I clicked the install believing that newer = better.
Unfortunately, now whenever I press F5 to execute my script, I get this error:
"The Debug Console is no longer used for PowerShell debugging. Please
use the 'PowerShell Integrated Console' to execute commands in the
debugger. Run the 'PowerShell: Show Integrated Console' command to
open it."
I can't say I've been smart enough to learn more than basics, and never really knew how to use the debugger, but I was getting by. With this error, however, does this mean that every time I want to execute my script, I have to press CTRL+` and then type out things like I was at a console window? For now, I've found a workaround by clicking in the editor window and pressing CTRL+a, F8. I was hoping to start reading an article on debugging, but it seems like the extension update has rendered the material obsolete.
This seems like a huge step back in terms of usability, but I'm not sure if it's really a bug for the extension developer, or I'm just not skillfull enough to use the extension?

All that happens now is the output is to the powershell integrated terminal. So make sure that the Terminal tab is active. Then hitting F5 works as normal (before).
My launch.json looks like:
{
"type": "PowerShell",
"request": "launch",
"name": "PowerShell Launch (current file)",
"script": "${file}",
"args": [],
"cwd": "${file}"
}

Related

prevent VS code notification: 'launch' is already running. Do you want to start another instance?

I'm writing an ui with tkinter (ttk), and if I run the my program while an other instance of the ui is open, VS code (starting today) started giving a (error) notification which looks like this:
I'm not sure but I think this started happening when I started using ttk (instead of only tkinter).
I know you're not meant to run multiple instances of your program, but while coding it's very convenient to be able to see what you're changing along the way, and not have to close your previous instance.
Is there a way to stop this notification of appearing?
Is there a way to stop this notification of appearing?
VSCode 1.71 (August 2022) should offer an option for that.
See issue 147912 and PR 147914
Add new launch config debug option for silent '{0}' is already running. Do you want to start another instance? confirm dialog.
Tested with simple launch config:
{
"command": "npm start",
"name": "Run npm start",
"request": "launch",
"type": "node-terminal",
"suppressMultipleSessionWarning": true
}
This is available in VSCode Insiders today.
I bound F5 to restart, so i only have to run it once, and to see changes i restart that instance (changed run to F7)

How to use ``OUTPUT`` in VSCode?

I've always used Sublime Text 3 for Python Coding, in which Build Systems were the only way of running a file.
Now I'm starting C++ programming, and I'm using VSCode. The problem I have is that, in that dock where:
PROBLEMS , OUTPUT , DEBUG CONSOLE , TERMINAL
The only thing I've had trouble with, is OUTPUT window, because nothing ever appears, so if I wanna run either Python or C++ code, it won't show anything to let me know what output would the program give. And if I just try to run it (pressing f5) it, it will open terminal and run it from it.
I saw something called Tasks but I don't know how they work, and they seem to be like Build Systems from Sublime Text 3.
I wanna use OUTPUT window, how can I get it working?
to run code in the output section of visual studio code you can use the extension Code Runner
just install, then press CTRL + ALT + N to run the file (supports c++ & python)
I wanna use OUTPUT window, how can I get it working?
As it stands now, you can not use the Output Window as a way to log code, that is reserved for native logs like Window, Main, Shared or Extensions to log their output using channels. There is a good candidate called the Debug Console.
You can log to the Debug Console using a launch.json configurable:
First, create a launch.json for your program.
Then add the following properties, in addition to whatever you need to get your program going:
internalConsoleOptions
Controls when the internal debug console should open
redirectOutput
Both of these used in tandem will open the 'Debug Console' instead of terminal and just provide the necessary output; though it still sends to terminal should you still want it:
"version": "0.2.0",
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"internalConsoleOptions": "openOnSessionStart",
"redirectOutput": true
}
]
For c++ they have an extensive tutorial on how to debug and run: https://code.visualstudio.com/docs/languages/cpp (in addition to setting up launch.json and tasks.json files respectively https://code.visualstudio.com/docs/cpp/config-mingw#_build-helloworldcpp)
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
ext install formulahendry.code-runner

VS Code opens a new debug console every time I build/run

Every time I build or run a program in VSCode a new python debug console is loaded. Before I know it I have 20+ and need to start deleting them. After 32 open consoles I get the error "The terminal process terminated with exit code: 256". I changed the terminal from the default console to git bash recently. How can I stop this?
A way around this issue is to stop VS Code from redundantly printing to the TERMINAL during debugging in the first place. Since it prints to the DEBUG CONSOLE as well, you can use that instead.
Change console to "none" "internalConsole" in each configuration in your project's launch.json file:
"configurations": [
{
"name": "Python: Current File",
"type": "python",
"request": "launch",
"program": "${file}",
"console": "internalConsole"
}
]
May 2019 Update: the "none" option was replaced by "internalConsole" so I edited my answer to reflect that. Here's the relevant GitHub Issue.
Adding "args": ["&&", "exit"], to launch.json remedies this for Git Bash. Certainly a hack, but I no longer have to manually close many debug terminals.
This may have been resolved in recent debug updates to core VS Code within the last year (as of 8/2022), but I was still seeing this intermittently.
I don't know if this will help the original poster, but I discovered that for me the issue persisted due to using Git Bash as the default terminal in Windows. Switching to Command Prompt as the default terminal fixed the issue. I haven't tested with other platforms or terminals.
Changing the default terminal to Command Prompt causes the Python extension to launch the "Python Debug" terminal with Command Prompt instead of Git Bash. I did log a VS Code/Python Extension defect about this. The initial response is that Git Bash is not officially supported currently.
There appears to be a communication problem between the Git Bash terminals and VS Code that causes this issue. Some of the characters between Git Bash and VS Code get dropped. Sometimes this mangles the debug command and I get and error and have to retry in addition to getting an extra debug window.
There is some additional background info and hacks to fix this from the past in this answer.
Hopefully fixed in the Insiders Build and should be in v1.54. See Debug opens a new integrated terminal for each Python session
. Test it in the Insiders Build if you can and report at the issue if it fixed/did not fix.
Actually you can delete all the instances of the terminal just by clicking on the trash can icon 🗑. If it does not work for the first time, restart the VS Code and try again.

How to debug an interactive Node.js app in VS Code?

How do you run and debug an interactive Node.js app (one that prompts the user to enter STDIN on the console) in VS Code using a simple launch (F5). I have so far been running the app using node --inspect-brk . and then attaching VS Code. This works fine, but I'm just wondering if there's a faster way. If I look at the DEBUG CONSOLE pane, I can see the STDOUT, but I can't add input there.
Randy's comment was my answer with a link here. Thanks, Randy.
The solution is to configure the console value in your launch.json file. I added "console": "integratedTerminal" and now when I hit F5 I can jump to the integrated terminal (CTRL+<backtick>) and interact with my app.

Does Visual Studio Code work with PowerShell in the Command Palette?

With Visual Studio Code (not the traditional Visual Studio IDEs), can you run PowerShell in the Command Palette? I ask because I commonly use it in the full IDE.
I have not seen PowerShell mentioned in the documentation, other than for basic syntax highlighting. I have tried it with no success. Is it unsupported, or is it an optional feature I can configure somehow?
Note: to those voting up the PowerGUI answer, it is not correct as it references the wrong edition of Visual Studio for this question. It is helpful if you are using the full IDE, but not the new editor named: Code.
This was the first problem I wanted to solve in VSCode. I did not find a way to
type PowerShell commands but I have found a way to create and run PowerShell tasks.
In the command palette type and choose Tasks: Configure Task Runner. It will
show you a json file configured for the default task runner.
I replaced the content with this
{
"version": "0.1.0",
"command": "PowerShell.exe",
"isShellCommand": true,
"args": [
"-NoProfile",
"Invoke-Build.ps1"
],
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "Test",
"isTestCommand": true,
"showOutput": "always"
},
{
"taskName": "Build, Test",
"showOutput": "always"
}
]
}
As a result in the command palette I can choose and run my predefined tasks (Build, Test, and combined Build, Test). I can add other tasks and probably bind them to some hotkeys. This is not exactly what I would like to have in VSCode for PowerShell but for the preview it is at least something.
P.S. This just my first experiment that somewhat worked. It is not perfect, more likely. There are many configuration parameters for this json file that I have not tried yet.
With version 0.10.1 of Visual Studio Code, you can run and debug PowerShell. Here is a sample launch.json that I use:
{
"version": "0.2.0",
"configurations": [
{
"name": "PowerShell",
"type": "PowerShell",
"program": "MyScript.ps1",
"args": "-Verbose"
}
]
}
Unfortunately, I cannot get the args to work (for more details, see: https://github.com/PowerShell/vscode-powershell/issues/24). Another problem I have is that Read-Host does not work with VS Code (for more details, see: https://github.com/PowerShell/vscode-powershell/issues/29). Definitely some rough edges.
Here's how you can configure the Powershell task to execute the currently opened .ps1 file without any Invoke-Build dependency:
{
"version": "0.1.0",
"command": "PowerShell.exe",
"isShellCommand": true,
"args": [
"${file}"
],
"tasks": [
{
"taskName": "Build",
"isBuildCommand": true,
"showOutput": "always"
},
{
"taskName": "Test",
"isTestCommand": true,
"showOutput": "always"
},
{
"taskName": "Build, Test",
"showOutput": "always"
}
]
}
Note: This is just a slight modification of Roman's answer (My edit to his answer was rejected).
Open the Debug view, in the View Bar select Debug from the View menu or press Ctrl + Shift + D.
In the Launch Configuration dropdown (shown in the following screenshot), select Add Configuration...
The launch.json configuration will open in the editor, type PowerShell and select the debug configurations you want, as shown in the following screenshot.
Save the launch.json file and select the debug configuration you want from the Launch Configuration dropdown:
Now you can debug PowerShell scripts through VSCode.
The Scripting Guys wrote a comprehensive 2 part blog post on this topic, like everything else they write, it's well worth a read if you're new to VSCode and PowerShell.
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/06/debugging-powershell-script-in-visual-studio-code-part-1/
https://blogs.technet.microsoft.com/heyscriptingguy/2017/02/13/debugging-powershell-script-in-visual-studio-code-part-2/
EDIT: I am aware that this question is several years old, but I came across it before I found any up to date information on how to set up PowerShell debugging in VSCode
As of version 0.10.3 there is now a PowerShell extension written by Microsoft that will enable writing PowerShell with IntelliSense and highlighting in Visual Studio Code
http://blogs.msdn.com/b/powershell/archive/2015/11/17/announcing-windows-powershell-for-visual-studio-code-and-more.aspx
At least in V1.4 (July 2016) this has been made a lot simpler.
The relevant documentation can be found here:
https://code.visualstudio.com/docs/editor/integrated-terminal
Essentially all you're doing is adding an entry to the settings.json file for User Settings.
Adding the following value:
// 64-bit PowerShell if available, otherwise 32-bit
"terminal.integrated.shell.windows":"C:\\Windows\\sysnative\\WindowsPowerShell\\v1.0\\powershell.exe"
IMG: Shows the User Settings settings.json file and the successful Integrated Console showing the PowerShell prompt:
An "Integrated Terminal" is now integrated into Visual Studio Code. This is a PowerShell Terminal in Windows. (Likely BASH in Linux / MacOS). The terminal appears in a panel at the bottom of the code editor, not in the Command Pallete.
Keyboard Shortcut to open Terminal: CTRL + `
Sources:
https://code.visualstudio.com/shortcuts/keyboard-shortcuts-windows.pdf
https://code.visualstudio.com/docs/getstarted/keybindings
I confirmed in version 1.19.2. Not sure when the feature was first integrated.
There is a much easier way to run PowerShell, no configuration needed:
Install the Code Runner Extension
Open the PowerShell code file in Text Editor, then use shortcut Ctrl+Alt+N, or press F1 and then select/type Run Code, or right click the Text Editor and then click Run Code in context menu, the code will run and the output will be shown in the Output Window.
Besides, you could select part of the PowerShell code and run the code snippet. Very convenient!
PowerGUI tool provides a nice interface to Visual Studio. The goal of this extension is to bring PowerShell development into Visual Studio.
Here is how it looks -
Along with IntelliSense, the PowerGUI Visual Studio Extension provides the following features and more to make it easier to work with PowerShell.
PowerShell file and project types: You can create/edit PowerShell code files and assemble them into projects with more than one file.
PowerShell code snippets: The code snippet feature can be used for PowerShell code.
PowerShell console window: This feature provides the PowerShell console environment within Visual Studio IDE. This allows you to run commands or view output of scripts. Figure B shows the console window opened in the IDE.
PowerShell debugging: This feature is why I installed the extension; it provides a way to debug scripts within Visual Studio. It's a straight-forward way to locate syntax or logical problems in a script.
Syntax highlighting and script analysis: These are more Visual Studio features made available to PowerShell development.
In order to install the PowerGUI Visual Studio Extension, PowerGUI must be installed, with the caveat that the correct version of each product is installed.
Download Here
It also provides Debugging facility which is the best part I like as a developer.
Thanks!