8

VSCode added a feature last year that will auto-run a task "on folder open". But what does "on folder open" mean when using workspaces?

Specifically, if you open a workspace, will "runOn": "folderOpen" tasks run? If so, how?

I'm asking because I configured a task to be auto-run, but it's not running when I open the workspace. (The task runs correctly when triggered manually.)

2 Answers 2

19

"On folder open" tasks will run when you open a workspace, just like when you use the "Open Folder..." link when opening a non-workspace folder.

However, there's an additional step required: you need to opt into auto-run tasks. I figured this out via subtle hint in the documentation which said this:

everyone who allows tasks to be run automatically

That made me wonder how to enable tasks to run automatically. It turns out there's a configuration change you need to make, as follows:

  1. Open the command palette (SHIFT+CMD+P) and choose "Tasks: Manage Automatic Tasks in Folder" enter image description here

  2. Choose "Allow Automatic Tasks in Folder" enter image description here

  3. Now close and re-open the workspace, and on-folder-open tasks will run as expected.

Frustratingly, this setting is not present in the usual JSON settings files, which means that it won't show up in the search of Settings. enter image description here

This made me waste a bunch of time trying to find this setting, which is why I'm posting a Q&A pair here to help the next victim of this problem.

UPDATE: I also suggested that VSCode add this to Settings. https://github.com/microsoft/vscode/issues/64618#issuecomment-554072124

If you run the task manually first, you might see a reminder/toast message that allows you to give the permission to "runOn": "folderOpen": VSCode task with runOn:folderOpen, after being run once manually, prompts you to give permission

2
  • 1
    I was looking at the settings.json as well. Thanks!
    – Marco
    Feb 26, 2021 at 11:51
  • Does someone know what is the corresponding .vscode/settings.json key for this feature?
    – lonix
    Jul 11, 2022 at 4:47
2

The mentioned issue 64618 is now closed, for VSCode 1.70 (July 2022), with PR 154171

add allow automatic tasks setting

New setting task.allowAutomaticTasks.on' with values:

  • Always/auto: Prompt for permission for each folder
  • Never/off: Enable automatic tasks in the folder.

It is available today in VSCode Insiders.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.