如何使用tasks.json

时间:2016-09-12 12:55:04

标签: visual-studio typescript asp.net-core visual-studio-code

我正在使用Visual Studio Code(vscode),这是一个在Visual Studio 2015(VS Proper)中初始化的asp.net核心项目。当我在vscode中设置它时,初始过程包括在tasks.json中添加这个自动生成的构建任务:

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}\\project.json"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        }
    ]
}

但是我使用的是打字稿,所以我希望它能够编译。我输入"配置任务运行器"进入命令托盘(仅在重命名tasks.json之后,因为它创建了一个同名的文件)并配置了如下所示的typescript任务:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "0.1.0",
    "command": "tsc",
    "isShellCommand": true,
    "args": ["-p", "."],
    "showOutput": "silent",
    "problemMatcher": "$tsc"
}

然后当我建立时,我的打字稿编写得很好,但我没有得到真正的#34;构建" ......

不起作用的直观解决方案:

{
    "version": "0.1.0",
    "command": "dotnet",
    "isShellCommand": true,
    "args": [],
    "tasks": [
        {
            "taskName": "build",
            "args": [
                "${workspaceRoot}\\project.json"
            ],
            "isBuildCommand": true,
            "problemMatcher": "$msCompile"
        },
        {
            "taskName": "tsc",
            "isBuildCommand": true,
            "args": ["-p", "."],
            "showOutput": "silent",
            "problemMatcher": "$tsc"

        }
    ]
}

如何在每次构建时都能完成这两个过程? 有希望的链接对我没有帮助:

https://github.com/Microsoft/vscode/issues/981

How to define several typescript compile tasks in one tasks.json?

1 个答案:

答案 0 :(得分:0)

此功能请求仍处于打开状态,请参阅:https://github.com/Microsoft/vscode/issues/981

解决此问题的最佳方法是使用像grunt,gulp甚至npm这样的任务运行器来运行您的不同任务。在tasks.json中,您可以按taskname定义构建和测试命令,并为每个任务设置问题匹配器。