javascript - visual studio code clean task - Stack Overflow

admin2025-04-17  0

I'm working in Visual Studio Code in Ubuntu on my Typescript project. And I'm wondering is there any possibility to execute some kind of 'clean' task. Here's my tasks.json

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

And here's my project structure.

Executing task clean says there's no such files or directory, while executing 'pwd' instead of rm says that I'm in the root of my project. Any suggestions how does this build system work? Maybe there's some special syntax for env variables in VS Code?

I'm working in Visual Studio Code in Ubuntu on my Typescript project. And I'm wondering is there any possibility to execute some kind of 'clean' task. Here's my tasks.json

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

And here's my project structure.

Executing task clean says there's no such files or directory, while executing 'pwd' instead of rm says that I'm in the root of my project. Any suggestions how does this build system work? Maybe there's some special syntax for env variables in VS Code?

Share asked Jun 21, 2017 at 8:42 IliaIlia 3411 gold badge3 silver badges13 bronze badges
Add a ment  | 

3 Answers 3

Reset to default 2

After VSCode 1.14, we have a new tasks manager in VSCode. I'm using .NET Core on ubuntu and I have a build and a clean tasks like this:

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

Both tasks works as expected.

I have also been looking for this, but as far as I understand, it's not possible to have more than one task in tasks.json. You can have a tasks array, but that only contains different mand line parameters for the same task. This example has the 'echo' task, and you can call it with different parameters. If you call the task 'hello' then 'echo Hello World' will be executed:

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

Have you tried using workspace variables? ${workspaceRoot} might be particular useful for you.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1744857752a270930.html

最新回复(0)