问题
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.)
回答1:
"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:
Open the command palette (SHIFT+CMD+P) and choose "Tasks: Manage Automatic Tasks in Folder"
Choose "Allow Automatic Tasks in Folder"
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.
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
来源:https://stackoverflow.com/questions/58866184/what-does-on-folder-open-mean-in-vscodes-run-on-folder-open-tasks