登录
首页 >  Golang >  Go问答

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

来源:stackoverflow

时间:2024-04-24 19:03:36 403浏览 收藏

你在学习Golang相关的知识吗?本文《使用运行/运行和调试 (F5/CTRL+F5) VS 代码选项时,如何配置 Visual Studio Code 来运行已编译的 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 构建任务来编译项目

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

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 code(可能不相关)。

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


解决方案


假设我的主包位于工作区的根文件夹中,我总是定义相同的 .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": []
        }
    ]
}

从那里,我可以从任何地方/任何文件按 f5,调试会话就会开始。

今天带大家了解了的相关知识,希望对你有所帮助;关于Golang的技术知识我们会一点点深入介绍,欢迎大家关注golang学习网公众号,一起学习编程~

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>