【问题标题】:visual studio code clean taskVisual Studio 代码清理任务
【发布时间】:2017-06-21 08:42:40
【问题描述】:

我在我的 Typescript 项目中使用 Ubuntu 中的 Visual Studio Code。我想知道是否有可能执行某种“clean”任务。 这是我的tasks.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "tasks": [
        {
            "taskName": "tsc",
            "command": "tsc",
            "isShellCommand": true,
            "isBackground": true,
            "problemMatcher": "$tsc"
        },
        {
            "taskName": "clean",
            "linux": {
                "command": "rm",
                "args": [
                    "./src/*.js"
                ],
                "isShellCommand": true
            },
            "isShellCommand": true,
            "isBackground": true
        }
    ]
}

这是我的项目结构。

执行task clean 表示没有这样的文件或目录,而执行'pwd' 而不是rm 表示我在项目的根目录中。 任何建议这个构建系统如何工作?也许 VS Code 中的环境变量有一些特殊的语法?

【问题讨论】:

    标签: javascript linux typescript visual-studio-code


    【解决方案1】:

    在 VSCode 1.14 之后,我们在 VSCode 中有了一个新的任务管理器。我在 ubuntu 上使用 .NET Core,我有一个 build 和一个 clean 这样的任务:

    {
        "version": "2.0.0",
        "tasks": [
            {
                "label": "build",
                "type": "process",
                "command": "dotnet",
                "args": [
                    "build",
                    "MyProj.csproj"
                ],
                "options": {
                    "cwd": "${workspaceFolder}/src/MyProj/"
                },
                "problemMatcher": "$msCompile"
            },
            {
                "label": "clean",
                "type": "shell",
                "linux": {
                    "command": "rm",
                    "args": [
                        "-rfv",
                        "bin/*",
                        "obj/*"
                    ]
                },
                "windows": {
                    "command": "del",
                    "args": [
                        "/S /Q",
                        "bin/*",
                        "obj/*"
                    ]
                },
                "options": {
                    "cwd": "${workspaceFolder}/src/MyProj/"
                },
                "problemMatcher": []
            }
        ]
    }
    

    两项任务都按预期工作。

    【讨论】:

      【解决方案2】:

      我也一直在寻找这个,但据我了解,tasks.json 中不可能有多个任务。您可以有一个任务数组,但它只包含同一任务的不同命令行参数。这个例子有'echo'任务,你可以用不同的参数调用它。如果你调用任务'hello',那么'echo Hello World'将被执行:

      {
          "version": "0.1.0",
          "command": "echo",
          "isShellCommand": true,
          "args": [],
          "showOutput": "always",
          "echoCommand": true,
          "suppressTaskName": true,
          "tasks": [
              {
                  "taskName": "hello",
                  "args": ["Hello World"]
              },
              {
                  "taskName": "bye",
                  "args": ["Good Bye"]
              }
          ]
      }
      

      【讨论】:

        【解决方案3】:

        您是否尝试过使用workspace variables${workspaceRoot} 可能对你特别有用。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2012-07-31
          • 2017-09-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多