tasks.json
taks.json文件一般用來設定build環境,通過Terminal > Configure Default Build Task呼出task.json文件,官網給出的例子如下:
{ "version": "2.0.0", "tasks": [ { "type": "shell", "label": "cl.exe build active file", "command": "cl.exe", "args": [ "/Zi", "/EHsc", "/Fe:", "${fileDirname}\\${fileBasenameNoExtension}.exe", "${file}" ], "problemMatcher": ["$msCompile"], "group": { "kind": "build", "isDefault": true } } ] }
這里command用來指定要執行的程序,args字段用於記錄執行command需要涉及到的參數。isDefault = true指定該tasks.json是(command + shift + b)快捷鍵執行的默認task。這里有更多詳細的task.json的參數介紹。
lauch.json
用來debug程序,快捷鍵為f5,通過Run > Add Configuration呼出lauch.json。官方給出的案例如下:
{ "version": "0.2.0", "configurations": [ { "name": "cl.exe build and debug active file", "type": "cppvsdbg", "request": "launch", "program": "${fileDirname}\\${fileBasenameNoExtension}.exe", "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": false, "preLaunchTask": "cl.exe build active file" } ] }
program字段用來制定需要執行的程序。其余字段詳見這里。
debug的例子還是看官方文檔比較好,https://code.visualstudio.com/docs/cpp/config-msvc#_step-through-the-code