Skip to content

Invoke Task from VSCode

Roman Kuzmin edited this page Feb 22, 2018 · 9 revisions

Invoke-TaskFromVSCode.ps1 invokes the current task from the current build script opened in VSCode. It is invoked in the session (by default) or in an external console (with the switch Console). The current task is the task at the caret or above. If there is none then the default task is invoked.

The script requires the VSCode PowerShell extension.

Configure launch.json or the global launch setting so that F5 invokes the current task. See Debugging Tips for the sample launch.json entry. This is probably the simplest way of using the script: edit a task, press F5, the task is invoked. If you have set some breakpoints then they break into the debugger when hit, otherwise the task just works.

Alternatively, you can invoke the script directly from the integrated console or register it as one of PowerShell.ShowAdditionalCommands and choose it there.

How to register commands. Create or open your VSCode profile (see $profile) and add one or two commands:

Register-EditorCommand -Name IB1 -DisplayName 'Invoke task' -ScriptBlock {
    Invoke-TaskFromVSCode.ps1
}

Register-EditorCommand -Name IB2 -DisplayName 'Invoke task in console' -SuppressOutput -ScriptBlock {
    Invoke-TaskFromVSCode.ps1 -Console
}

NB You can add a keyboard shortcut for PowerShell.ShowAdditionalCommands.