VS code:Task

Task

微软官方连接: https://code.visualstudio.com/docs/editor/tasks

what is Task

我们知道,vscode可以支持许多编程语言,很多语言是需要进行编译的,打包,测试…
有许多已有的工具支持这些流程,例如Ant, Make, Jake, and MS build.
VS code:Task_第1张图片
这些工具的特性:

  • 命令行形式
  • 在整个开发流程的内或者 开发流程外运行。(edit, compile, test and debug)

因为这些工具在整个开发过程中扮演着重要的角色,所以vscode需要某种形式支持这些工具。
Task 可以配置运行脚本,因此他可以被用于run这些工具。

运行脚本的文件是task,json , 位于.vscode文件夹下

如何生成task.json文件

1, 右边的导航栏目,第四个tab, --> 点击Run and Debug
VS code:Task_第2张图片
2, 这时候去top search 栏,选择你本地安装的编译器。
如果本地没有安装gcc, 可以去搜下如何安装
VS code:Task_第3张图片
3, 当你选择之后,这时候生成launch.json 文件, 也会生成task.json文件。
launch.json 和 task,json 的区别 https://blog.csdn.net/weixin_44465434/article/details/123372132

我发现有时候并不会生成task.json.

3-1
top search 栏。

  • 输入: > (表示将要运行命令)
  • 输入 configure task
    VS code:Task_第4张图片
    之后就会生成task.json

或者搜 tasks
VS code:Task_第5张图片
或者, 输入命令 Run Task 然后因为目前没有tasks.json文件,所以会提示让你创建,这时候可以选择cmke或者普通的cpp 等.
==> 这里并不会让你自动创建。这里是运行的功能
VS code:Task_第6张图片
VS code:Task_第7张图片

总体感觉还是很麻烦的。然后这里生成的tasks.json 很可能不能用。

Tasks 语法

{
  // See https://go.microsoft.com/fwlink/?LinkId=733558
  // for the documentation about the tasks.json format
  "version": "2.0.0",
  "tasks": [
    {
      "label": "Run tests",
      "type": "shell",
      "command": "./scripts/test.sh",
      "windows": {
        "command": ".\\scripts\\test.cmd"
      },
      "group": "test",
      "presentation": {
        "reveal": "always",
        "panel": "new"
      }
    }
  ]
}
  • label: The task’s label used in the user interface
  • type: he task’s type. For a custom task, this can either be shell or process. If shell is specified, the command is interpreted as a shell command (for example: bash, cmd, or PowerShell). If process is specified, the command is interpreted as a process to execute.
  • command: The actual command to execute.
  • windows: Any Windows specific properties. Will be used instead of the default properties when the command is executed on the Windows operating system
  • group: Defines to which group the task belongs. In the example, it belongs to the test group. Tasks that belong to the test group can be executed by running Run Test Task from the Command Palette.
  • options: Override the defaults for cwd (current working directory), env (environment variables), or shell (default shell). Options can be set per task but also globally or per platform. Environment variables configured here can only be referenced from within your task script or process and will not be resolved if they are part of your args, command, or other task attributes.
  • presentation: Defines how the task output is handled in the user interface. In this example, the Integrated Terminal showing the output is always revealed and a new terminal is created on every task run.
  • runOptions: Defines when and how a task is run.

task json schema

c++ task module

{
  "version": "2.0.0",
  "tasks": [
    {
      "label": "build",
      "command": "gcc",
      "args": ["-Wall", "helloWorld.c", "-o", "helloWorld"],
      "problemMatcher": {
        "owner": "cpp",
        "fileLocation": ["relative", "${workspaceFolder}"],
        "pattern": {
          "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
          "file": 1,
          "line": 2,
          "column": 3,
          "severity": 4,
          "message": 5
        }
      }
    }
  ]
}

How Task used in C++

快捷键ctrl +shift+B 或者top search menu --> run task --> 找到合适的
或者在底层的terminal 输入 Run Build Task

How to run the tasks.json 文件

VS code:Task_第8张图片

你可能感兴趣的:(C++,vscode)