Skip to content

Generate VSCode Tasks

Roman Kuzmin edited this page Nov 15, 2017 · 13 revisions

The script New-VSCodeTask.ps1 generates VSCode tasks bound to the specified or default build script and the specified or global Invoke-Build as the task runner.

The default task becomes the so called VSCode build task which is invoked by Ctrl+Shift+B. The default task is "." if it exists, otherwise it is the first task.

To invoke another task, use F1 or Ctrl+Shift+P and type Run Task. Then type a task name or select it from the task list. Or set your keyboard shortcut for workbench.action.tasks.runTask.

Only tasks with certain names are included. They contain alphanumeric characters, "_", ".", and "-", with the first character other than "-".


Handy output links

Build errors are shown in the VSCode output window with links to the problem and related task locations. Use Ctrl-Click to open the source.


How to use the script

Step 1. Change the current location to your VSCode workspace directory. The new file to be created is .vscode/tasks.json. The existing file is replaced.

Step 2. Invoke New-VSCodeTask.ps1.

If the default build script is in the workspace root directory, Invoke-Build.ps1 is in the workspace or subdirectory or in the path or available as the module command then parameters are not needed:

New-VSCodeTask

Otherwise, specify the parameter BuildFile or InvokeBuild or both. If the workspace directory is not going to be moved then absolute paths may be used. Otherwise paths relative to the workspace should be be used. For example:

New-VSCodeTask ./Scripts/Build.ps1 ./packages/InvokeBuild/Invoke-Build.ps1

Note that in the above example the second argument makes sense only if there are several versions of Invoke-Build.ps1 in the workspace for some reasons. Otherwise Invoke-Build.ps1 will be discovered, the argument is not needed.

NOTES

When you generate VSCode tasks make sure you do not have anything important in your .vscode/tasks.json. The file is replaced.

Do not edit the generated file. Modify the build script instead. VSCode tasks do not have to be regenerated on every change. This is needed only when tasks are added, removed, renamed, or script locations change.