VS Code tasks.json——任务单独工作,但不合并
这让我快发疯了。生成/运行文件正确,fmt命令正确。但如果我试图合并到一个任务文件中,它就会停止工作 这两个人单独工作很好,按照我想要的方式行事: tasks.jsonVS Code tasks.json——任务单独工作,但不合并,json,go,visual-studio-code,vscode-tasks,Json,Go,Visual Studio Code,Vscode Tasks,这让我快发疯了。生成/运行文件正确,fmt命令正确。但如果我试图合并到一个任务文件中,它就会停止工作 这两个人单独工作很好,按照我想要的方式行事: tasks.json { "version": "0.1.0", "isShellCommand": true, "showOutput": "always", "command": "go", "taskName": "build", "args": [ "build", "-o", "${workspaceRoot}.ex
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "build",
"args": [
"build",
"-o",
"${workspaceRoot}.exe",
"&&",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
}
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "fmt",
"args": [
"fmt",
"${file}"
],
"isBuildCommand": true
}
{
"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}"
]
}
]
}
tasks.json
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "build",
"args": [
"build",
"-o",
"${workspaceRoot}.exe",
"&&",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
}
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "fmt",
"args": [
"fmt",
"${file}"
],
"isBuildCommand": true
}
{
"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}"
]
}
]
}
但是合并到一个文件中,它将不起作用:
tasks.json
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "build",
"args": [
"build",
"-o",
"${workspaceRoot}.exe",
"&&",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
}
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"taskName": "fmt",
"args": [
"fmt",
"${file}"
],
"isBuildCommand": true
}
{
"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)
我似乎不明白为什么它是一种方式,而不是另一种方式。第二种方法(用于组合任务)概述如下:
答:问题在于,当“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": [
"-x",
"-o",
"${workspaceRoot}.exe"
],
"isBuildCommand": true
},
{
"taskName": "fmt",
"args": [
"${file}"
]
}
]
}
您应该添加属性
suppressTaskName
删除多余的build
参数的OPs解决方案显然是有效的,但是,它涵盖了以下示例:
我们将suppressTaskName
设置为true,因为默认情况下,任务名称也会传递给命令,这将导致“echo hello World”
我最喜欢的构建任务是:
{
"version": "0.1.0",
"isShellCommand": true,
"showOutput": "always",
"command": "go",
"echoCommand": true ,
"options": {
"cwd": "${fileDirname}"
},
"tasks": [
{
"taskName": "build",
"args": [
"build",
"-x"
],
"isBuildCommand": true,
"suppressTaskName": true
}
]
}
添加“&&”,“${workspaceRoot}.exe”对我来说很有用。我猜问题与我再次在args中列出taskname有关。谢谢大家!@victoroux这让我了解了vscode中的这个功能,我不知道,所以谢谢:)