使用vscode调试wails项目(golang桌面GUI)

文章目录

  • [安装 Golang 环境](#安装 Golang 环境)
  • [安装 NPM](#安装 NPM)
  • [安装 VSCode](#安装 VSCode)
  • [安装 Go 插件](#安装 Go 插件)
  • [安装 Go 插件依赖工具](#安装 Go 插件依赖工具)
  • [安装 Wails](#安装 Wails)
  • 准备项目
  • [Visual Studio Code 配置安装和构建步骤](#Visual Studio Code 配置安装和构建步骤)
  • 参考资料

安装 Golang 环境

访问 golang 官网下载环境安装包:https://go.dev/dl/

安装 NPM

Node 下载页面 下载 NPM。 最好使用最新版本,因为这是我们通常会测试的版本。

运行 npm --version 进行验证。

安装 VSCode

VsCode 的安装就更加容易,直接在官网下载软件包按照指引安装即可。

https://code.visualstudio.com/

安装 Go 插件

VSCode 的插件功能中输入 go 关键字,然后找到下图中的插件,并安装。

安装 Go 插件依赖工具

快捷键 Ctrl + Shift + p 打开命令面板,输入go install tools,选择第一项 Go: install/Update Tools

安装 Wails

运行 go install github.com/wailsapp/wails/v2/cmd/wails@latest 安装 Wails CLI。

系统检查

运行 wails doctor 将检查您是否安装了正确的依赖项。 如果没有,它会就缺少的内容提供建议以帮助纠正问题。

准备项目

bash 复制代码
# 下载项目
git clone https://github.com/obity/hiposter.git
# 进入项目目录
cd hiposter
# 进入项目前端目录
cd frontend
# 安装nodejs依赖
npm install
npm run dev
cd ..
go build -tags dev -gcflags "all=-N -l"
wails dev

Visual Studio Code 配置安装和构建步骤

bash 复制代码
mkdir .vscode && touch .vscode/launch.json && touch .vscode/tasks.json

lanuch.json

复制代码
{
    // 使用 IntellliSense 来了解可能的属性。
    // 悬停以查看现有属性的描述。
    // 更多详情访问:https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Wails: Debug myproject",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            "program": "${workspaceFolder}/build/bin/myproject.exe",
            "preLaunchTask": "build",
            "cwd": "${workspaceFolder}",
            "env": {}
        }
    ]
}

文件tasks.json

复制代码
{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "ui:install",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/frontend"
            },
            "presentation": {
                "clear": true,
                "panel": "shared",
                "showReuseMessage": false
            },
            "isBackground": true,
            "command": "pnpm",
            "args": [
                "install"
            ]
        },
        {
            "label": "ui:build",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}/frontend"
            },
            "presentation": {
                "clear": true,
                "panel": "shared",
                "showReuseMessage": false
            },
            "isBackground": true,
            "command": "pnpm",
            "args": [
                "build"
            ]
        },
        {
            "label": "build",
            "type": "shell",
            "options": {
                "cwd": "${workspaceFolder}"
            },
            "command": "go",
            "args": [
                "build",
                "-tags",
                "dev",
                "-gcflags",
                "all=-N -l",
                "-o",
                "build/bin/myproject.exe"
            ],
            "dependsOn": [
                "ui:install",
                "ui:build"
            ]
        }
    ]
}

vscode调试图片如下

参考资料

在 VS Code 中调试
vscode launchjson-attributes
使用 VSCode 开发 Golang 代码,并支持 debug断点调试
wails-v2-examples
wails 手动构建
vscode-go/wiki/debugging
集成开发环境

相关推荐
福大大架构师每日一题5 小时前
ragflow v0.27.0 发布:Go 后端全面对齐、智能体搜索与知识编译大升级,超全更新解析
开发语言·后端·golang
JavaPub-rodert5 小时前
Go 后台如何同时兼容 MySQL、PostgreSQL、SQLite 和 SQL Server?从 ShiyuAdmin 看 GORM 多数据库适配
数据库·mysql·postgresql·golang·javapub·王仕宇
sunoo-2298 小时前
C 语言文件 IO 全攻略:从基础函数到实战踩坑(BMP 读取 + 词典查询)
linux·c语言·前端·笔记·vscode·学习
慕容引刀9 小时前
或许你真的需要这个Git神器:让团队提交文案终于对齐了
人工智能·git·vscode·自然语言处理·github
00后程序员张10 小时前
iOS 开发全流程需要哪些工具?编码、调试、构建、发布阶段选择
ide·vscode·ios·objective-c·个人开发·swift·敏捷流程
nicehuai10 小时前
烧录、查变量、看日志、调驱动:H-FlashScope搞定嵌入式下载调试的瑞士军刀
ide·vscode·visual studio
剩下了什么19 小时前
float32 与 float64 精度陷阱:如何在 Go 中避免错误使用
开发语言·后端·golang
ttwuai1 天前
Go 后台接入 SSO 后菜单正常但接口 403,怎么排查权限链路?
开发语言·后端·golang
PC2005-cloud1 天前
Go学习笔记:基本概念与项目结构——GOPATH、Go Modules 与常用命令
笔记·学习·golang
ttwuai1 天前
Go 后台图片上传到对象存储后,预览 403/404 怎么排查?
开发语言·golang