这让我发疯(发疯!)。构建/运行文件正确且 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)
我似乎无法理解为什么它以一种方式工作,但不能以另一种方式工作。此处概述了第二种方法(用于组合任务):在 VSCode 中定义多个任务
回答:问题在于添加“build”或“fmt”作为参数,而它已经被列为任务名称。我不知道 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}"
]
}
]
}