使用Run / Run&DebugF5 / CTRL + F5VS代码选项时,如何配置Visual Studio代码以运行已编译的Go代码?

问题描述

我已根据此博客文章安装了以下任务来编译Go项目:https://robertbasic.com/blog/build-and-run-golang-projects-in-vs-code/

tasks.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
            }
        }
    ]
}

现在我可以使用Terminal> Run build task

来编译项目。

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

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": "${fileDirname}","cwd": "${workspaceRoot}","args": [],"env": {}
        }
    ]
}

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

package .: no Go files in /usr/home/username/projects/my_app/.vscode
Process exiting with code: 1 signal: false

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

使用F5 / CTRL + F5时,我该怎么做才能使程序运行? 欢迎任何提示包括建议的帮助部分或博客条目。

解决方法

假设我的主软件包位于工作空间的根文件夹中,那么我总是定义相同的//Test.js describe("Reuse code here",function(){ it("Want to reuse this test case ",customReusableFunction) }) function customReusableFunction(){ // do stuff here }

.vscode/launch.json

从那里,我可以从任何位置/任何文件中按 F5 ,调试会话就开始了。