使用运行/运行和调试 (F5/CTRL+F5) VS 代码选项时,如何配置 Visual Studio Code 来运行已编译的 Go 代码?

M.E*_*.E. 6 go visual-studio-code

我按照这篇博文安装了以下任务来编译我的 Go 项目:https://robertbasic.com/blog/build-and-run-golang-projects-in-vs-code/

任务.json

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "Build Go",
            "type": "shell",
            "command": "go build",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

现在我可以使用“终端”>“运行构建任务”来编译项目

为了运行和调试,我创建了:

启动.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${fileDirname}",
            "cwd": "${workspaceRoot}",
            "args": [],
            "env": {}
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

但它不起作用,我收到以下消息:

package .: no Go files in /usr/home/username/projects/my_app/.vscode
Process exiting with code: 1 signal: false
Run Code Online (Sandbox Code Playgroud)

FreeBSD12.1 下的 Visual Studio Code(可能不相关)。

使用 F5/CTRL+F5 时我需要做什么才能让程序运行?欢迎任何提示,包括推荐的帮助部分或博客条目。

Von*_*onC 18

假设我的主包位于工作区的根文件夹中,我总是定义相同的.vscode/launch.json

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [

        {
            "name": "Launch",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceFolder}",
            "env": {},
            "args": []
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

从那里,我可以F5从任何地方/任何文件按下,然后调试会话就开始了。