Create tasks in Visual Studio Code per user

2k Views Asked by At

When I created a Node task for Visual Studio Code it created a tasks.json file inside the .settings folder for the folder that you have open (node-app in this case as shown in the image below). ie: it creates a task per folder.

{
    "version": "0.1.0",
    "command": "node",
    "isShellCommand": true,
    "args": ["${file}"]
}

enter image description here

My question is how do you create a task per user rather than a project based task so that I can execute the node code from any folder rather that having to create the same task for each folder you open in Visual Studio Code.

Also how do you execute individual files without opening a folder.

1

There are 1 best solutions below

0
On

It looks like this will be in v1.42, the January 2020 release. See https://github.com/microsoft/vscode/issues/89343 (user level tasks). And https://github.com/microsoft/vscode/issues/1435.

In addition to having tasks in your .code-workspace file and in tasks.json in your open folder, you can now have tasks in a user level tasks.json next to your user settings.json.

Open a folder that has some tasks. The vscode project is a good example.

Run the Open User Tasks command to create a tasks.json file next to your user settings.json file.

Add a shell or process type task to the new tasks.json. Only those two types of task are supported here.

Run the Run Task command and verify that you see your new user level task. Verify that you can tell that it's a user level task in the task quick pick. Verify that you can configure your user level task by clicking the gear next to it in the quick pick. Verify that you can run the user task.

It is in the Insiders' Build already so presumably v1.42.

------- From the 1.42 release notes:

User level tasks

Tasks declared in tasks.json are now supported at the User Settings level. If you have a build script that you use across many projects, or if you don't want your tasks in a project folder, you can add your tasks in the user tasks.json file. You can run the Tasks: Open User Tasks command to create user level tasks. These tasks will be available across all folders and workspaces. Only the shell and process task types are supported here.