json - VS Code tasks.json——任务单独工作,但不组合

标签 json go visual-studio-code vscode-tasks

这让我抓狂(抓狂!)。构建/运行文件正确,fmt 命令正确。但是,如果我尝试合并到一个任务文件中,它就会停止工作。

这两个独立运行良好,并且按照我想要的方式运行:

任务.json

{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "build",
"args": [
    "build",
    "-o",
    "${workspaceRoot}.exe",
    "&&",
    "${workspaceRoot}.exe"
],
"isBuildCommand": true
}

任务.json

{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "fmt",
"args": [
    "fmt",
    "${file}"
],
"isBuildCommand": true
}

但是合并成一个文件,就不行了:

任务.json

{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"tasks": [
    {
        "taskName": "build",
        "args": [
            "build",
            "-o",
            "${workspaceRoot}.exe",
            "&&",
            "${workspaceRoot}.exe"
        ],
        "isBuildCommand": true
    },
    {
        "taskName": "fmt",
        "args": [
            "fmt",
            "${file}"
        ]
    }
]
}

构建时出现错误:

can't load package: package build: cannot find package "build" in any of:
    D:\dev\Go\src\build (from $GOROOT)
    D:\dev\Gopher\src\build (from $GOPATH)
can't load package: package -o: cannot find package "-o" in any of:
    D:\dev\Go\src\-o (from $GOROOT)
    D:\dev\Gopher\src\-o (from $GOPATH)
can't load package: package d:/dev/Gopher/src/myproject.exe: cannot find package "d:/dev/Gopher/src/myproject.exe" in any of:
    D:\dev\Go\src\d:\dev\Gopher\src\myproject.exe (from $GOROOT)
    D:\dev\Gopher\src\d:\dev\Gopher\src\myproject.exe (from $GOPATH)

我似乎无法理解为什么它以一种方式工作,而另一种方式却不行。此处概述了第二种方法(用于组合任务):Define multiple tasks in VSCode


答案:问题在于添加“build”或“fmt”作为 args 时它已被列为任务名称。我不知道那是 taskname 的工作方式。允许用户开发而不用担心愚蠢的 Windows 防火墙的最终工作产品:

tasks.json(感谢@not-a-golfer 的最终和工作)

{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"echoCommand": true ,
"tasks": [
    {
        "taskName": "build",
        "args": [
            "-o",
            "${workspaceRoot}.exe",
            "&&",
            "${workspaceRoot}.exe"
        ],
        "isBuildCommand": true
    },
    {
        "taskName": "fmt",
        "args": [
            "${file}"
        ]
    }
]
}

最佳答案

以下似乎有效,但您似乎无法使用 && 链接运行:

{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"echoCommand": true ,
"tasks": [
    {
        "taskName": "build",
        "args": [
            "-x",
            "-o",
            "${workspaceRoot}.exe"
        ],
        "isBuildCommand": true
    },
    {
        "taskName": "fmt",
        "args": [
            "${file}"
        ]
    }
]
}

关于json - VS Code tasks.json——任务单独工作,但不组合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35343143/

相关文章:

javascript - JSON是否存储格式化文本并保持格式

go - 无法获取套餐

windows - goapp 服务 : unable to find dev_appserver. py

javascript - 如何将 json 中数字数组的字符串版本转换为 javascript 中的数字数组

json - Logstash 删除类型并保留 _type

java - 如何实现搜索 View

go - 为什么返回 int 的函数文字不能分配给返回 interface{} 的函数?

python - Docker 开发环境,pylint 无法导入错误

typescript - VSCode 在编译时显示 .vue 导入的 "cannot find module"TS 错误

visual-studio-code - 有没有办法让 VS Code 'interpret' 成为具有不同语法的文件的一部分?