visual-studio - 如何使用 tasks.json 构建和编译 typescript

标签 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"
        }
    ]
}

但我使用的是 typescript ,所以我希望它能够编译。我在命令托盘中键入“Configure Task Runner”(仅在重命名 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"
}

然后当我构建时,我的 typescript 编译得很好,但我没有得到真正的“构建”...

无效的直观解决方案:

{
    "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?

最佳答案

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

解决这个问题的最佳方法是使用诸如 grunt、gulp 甚至 npm 之类的任务运行器来运行不同的任务。然后,在 tasks.json 中,您可以通过任务名称定义构建和测试命令,并为每个任务设置问题匹配器。

关于visual-studio - 如何使用 tasks.json 构建和编译 typescript ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39450820/

相关文章:

windows - SDK windows丛林

visual-studio - Windows 上的 AWS Beanstalk ebextensions

javascript - Angular2 和 SystemJS : Cannot find module while building a moduleLoader

javascript - 使用 React.forwardRef 时在 React/TypeScript 中给 ref 什么类型?

typescript - 异步不工作 Atom TypeScript

asp.net-core - 部署时未提供 Nuget 包内容文件

c++ - 通过宏强制执行编译器设置

c# - 每个 Controller 调用的 asp 中是否有一个钩子(Hook)来检查用户是否仍然有效?

.net - 当我得到一件商品时 $Expand 不起作用

visual-studio - Visual Studio 中的类设计器 - 值得吗?