vscode自定义task的一个例子

vscode task简介

vscode可以自定义task完成一些代码或者项目生成,编译,测试,打包等的工作。通过这种方式完成代码生产自动化,可以在做这些事情时不用临时再敲命令,或者写代码。

自定义task的本质还是通过在tasks.json中指定要调用的脚本或者命令。

tasks.json 位于目录.vscode

一个例子

下边是我编写的一个tasks.json的例子,完成了三件事,编译,发布所需的动态链接库的拷贝和zip。

项目是cmake自动生成的,之所以没有把cmake也包含进来,是因为vscode安装完cmake插件后,每次打开workspace或者修改cmakelists.txt都会自动运行cmake,所以治理就没有必要了。

{
     
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "options": {
     
        // 这里指定tasks 的运行目录,默认是${workspaceRoot},也就是.vscode/..
        "cwd": "${workspaceRoot}/build"
    },
    "tasks": [
        {
     
        // 这个task完成编译工作,调用的是MSBuild
            "label": "build",
            "type": "shell",
            "command": "MSBuild.exe",
            "args": ["svr.sln","-property:Configuration=Release"]
        },
        {
     
        // 这个task完成动态库的拷贝
        "label": "buildAll",
            "type": "shell",
            "command": "cp",
            "args": ["./src/odbc/Release/odbccpp.dll",
                 "./Release/odbccpp.dll"],
            "dependsOn":["build"], // depend可以确保build完成之后再做拷贝
        }
        ,
        {
     
        // 使用好压自动完成软件的zip工作
        "label": "product",
            "type": "shell",
            "command": "HaoZipC",
            "args": ["a",
                "-tzip",
                "./Product.zip",
                "./Release/*"],
            "dependsOn":["buildAll"],
        }
    ]
}

现在使用ctrl+shift+p, 然后>tasks: run task,然后product就可以了。也可以指定快捷键。

你可能感兴趣的:(vscode自定义task的一个例子)