Closed pcgeek86 closed 7 years ago
You can already set up multiple launch configurations that launch specific file paths, but launching .psd1 files isn't currently supported. I'll either add support for it or add an appropriate error message.
You can set up multiple configurations. In the Debug view, press the gear
icon to open your launch.json file. Now press the Add Configuration
button and pick the "PowerShell: Launch Script" and fill in the script you want to launch.
Also, be sure to check out my Scripting Guys Debugging in VS Code Part 2
blog post that goes live on Monday. It covers this in a fair amount of detail.
And for launching Pester tests - see #487. It can be made to work now but I'm not sure I would rely on it - which is why I didn't add support yet.
Sounds good, thanks. I'd suggest keeping this open for the purposes of tracking "launching" a .psd1 file. What exactly would that do? I would maybe throw an exception, saying that you can't launch a .psd1, maybe? Not sure I have the best solution, but the current exception certainly isn't immediately helpful.
Ideally it'd just call Import-Module with that path and drop you into the console.
On the extension, do we have a chance to inspect the "script":
arg before it gets sent to PSES? Either in VSCode or PSES we could test that A) the file exists (in case we allow an arg like Invoke-Pester
which isn't a file) and if it is a file that exists B) has to have certain extension: .ps1, .psd1, .psm1 etc. Right now, it will try to launch against any file type (.md, .yml, .json, etc).
Yep, check out this function:
https://github.com/PowerShell/vscode-powershell/blob/develop/src/features/DebugSession.ts#L26
If you want to stop execution from happening, skip the vscode.commands.executeCommand('vscode.startDebug'...)
call.
Should we initially not allow debugging of a .psd1
file? It's more of a data file and it might not even be a module manifest. It might be a string localization file. We could always come back later and enable .psd1
debugging.
Hmmm, good point. We can probably figure out whether it's a module manifest file, but not necessarily worth doing right now.
Why is this still not supported?
If you hit F5 to invoke the debugger, and currently have a PowerShell module manifest file open, a confusing exception is thrown, and captured in the Visual Studio Code Debug Console.
It'd be great to be able to set up multiple launch configurations, similar to how NPM works, so that hitting F5 isn't dependent on having the right file selected. For example, you might set up a launch configuration to invoke unit tests, or a separate one to publish the module to the PowerShell Gallery, etc. etc.
Cheers, Trevor Sullivan Docker Captain Microsoft MVP: Cloud & Data Center Management https://trevorsullivan.net https://twitter.com/pcgeek86