It isn’t strictly necessary to use Visual Studio Code to build your code. You can still drop to the command line and build it more directly. However, it is handy to be able to build with a shortcut key or not have to manage another window.
For my example code, I have a Makefile that I use with “make all” as the default target, and “make clean” to delete everything.
You can set up custom tasks within VSCode that can execute any shell command, even specifying which shell to use. There is a special “Default Build” task.
To start, select the “Task” menu, then “Configure Tasks”. If this is the first time, it will ask for a type – select “Others”; VSCode will create the .vscode/tasks.json file for you.
I have the following in my tasks.json file:
"taskName": "Make Clean",
"command": "make clean",
The first task just runs the command-line “make”. The Terminal pane will be opened to show the results. This is the default build task, so it can be performed using ctrl-shift-B.
The second task is similar, but it runs “make clean”. It doesn’t have a defined shortcut key. However, this can be performed by selecting Tasks/Run Task from the menu or alt-shift-B. You can then select from the defined tasks.
(VSCode does have configurable keybindings, so if you want to assign a task to a shortcut key, you can do this easily!)
A caveat: GNU Make does not play particularly well with Windows. While my current project Makefile does work, I have had other Makefiles that will not run under the Windows cmd shell. In those cases, I had to use the MinGW shell. While it is possible to specify other shell executables from the tasks.json file, I have not figured out how use the MinGW shell. The new Linux Subsystem could be an alternative solution, but I have not yet tried it. This should work without problems on Linux and Mac.