44

I just start to use vscode in linux. I know that the build configuration are set in tasks.json. But where does this file locate?

I tried Ctrl-Shift-P then

tasks, no commands matching.

build, no commands matching.

I also tried to find it in ~/.vscode folder, nothing here!

Is there a way to find / open this file?

Nick
  • 8,451
  • 13
  • 57
  • 106

5 Answers5

57
  1. Open a folder with vscode
  2. Hit F1
  3. Select "Tasks: Configure Task"
  4. Hit Enter and vscode will create a sample tasks.json for you

enter image description here

mbomb007
  • 3,788
  • 3
  • 39
  • 68
Steffen
  • 3,327
  • 2
  • 26
  • 30
  • It creates it, but it also creates it in the ".vscode" directory, which Microsoft explicitly recommends against checking in. If you move it into the workspace root, which is supposedly supported, it doesn't work (at least for me). – breakpoint Mar 12 '19 at 11:14
  • this added the tasks.json file under .vscode, now i have to mention this in preLaunchTask, and if so how can i refere the task? – Sunil Garg Feb 09 '21 at 08:38
  • @SunilGarg The value of preLaunchTask should equal to the value of your task label – Steffen Feb 09 '21 at 08:56
18

DANGER! All of this has changed. Current Microsoft docs on this topic are NOT consistent. Note the version warning at the top of this:

https://code.visualstudio.com/docs/editor/tasks

Note the conflicts between this:

https://learn.microsoft.com/en-us/visualstudio/ide/customize-build-and-debug-tasks-in-visual-studio?view=vs-2017

and this:

https://code.visualstudio.com/docs/languages/cpp

I cannot get a straight answer on what works now (12MAR2019) to save my life, but I can tell you that none of the permutations I've tried, namely:

{., .vs, .vscode} / { tasks.json, tasks.vs.json}

are working for me. It really drives me crazy that they changed this crap without updating ALL of the pertinent documentation, and the backward-compatibility "support" is just making things MUCH WORSE.

breakpoint
  • 916
  • 9
  • 16
  • After opening VS Code I opened the directory containing my project (ROS workspace in this situation) and simply hit Ctrl-Shift-B to build. At this point it asked me "Select build task to run". It listed several options and an option for other. When I selected the other it prompted to create the tasks.json file and pre-populated with a default selection. I changed it to catkin and it's working just fine. – bakerhillpins Jun 20 '19 at 16:54
  • ADDENDUM: You've almost certainly noticed how much faster Visual Studio Code development proceeds than other projects. The above answer may very easily be obsolete at this point-- if you find out it is, please report. – breakpoint Sep 13 '20 at 20:14
6

2019 Version

New tasks version 2.0.0

Here's how to do it step by step


I compiled this from the documentation:

First i tried ⬆︎ ⌘ B ... This didn't work for me (I was following a YouTube tutorial... a bit outdated it seems).

After looking at the documetation i found that you have to initialize your typescript folder. To do so:

tsc --init - this will generate a file called tsconfig.json

The documentation said to run code . after you ran tsc --init. Mine worked without is as well as with it. Feel free to play with it and see what it changes cause i honestly don't know.

After that, move your mouse up to the toolbar (global Terminal menu.)... underneath the Terminal tab, click on the Configure Default Build Task...

then click on tsc: build and that will generate your tasks.json

Note that mine generated without the "version": "2.0.0" line... so if yours did the same that means your hardware is too old and you have to upgrade.... i'm kidding! ... Just add "version": "2.0.0", right above "tasks": [, and then you should be fine.

Community
  • 1
  • 1
PhillipJacobs
  • 2,337
  • 1
  • 16
  • 32
5

You have to create it manually. Current version of VS Code only creates launch.json automatically. The auto detect claims made in docs also don't work (for me at least).

Here is a sample file you can create in .vscode/tasks.json that defines gulpjs tasks:

{
    "version":"0.1.0",
    "command": "./node_modules/.bin/gulp",
    "isShellCommand": true,
    "tasks":[
        {
            "taskName": "test",
            "isTestCommand": true,
            "problemMatcher": "$gulp-tsc",
            "showOutput": "always"
        }
    ]
}
S.D.
  • 29,290
  • 3
  • 79
  • 130
1

Add C# extension from Microsoft. Post that open any cs file. It will install C# dependencies.The you will get a pop up

enter image description here

Click yes. Both tasks.json and launch .json are created.