Vscode Debug调试 Wails

不能调试吗?能调试吗?快点开始调试

Vscode Debug调试 Wails

By img Microanswer Create at:Oct 24, 2025, 5:44:32 PM 

Tags: vscode debug wails golang 桌面应用 ui 原生 跨平台

不能调试吗?能调试吗?快点开始调试


在vscode中调试wails的办法实现原理:通过添加一条vscode的【运行和调试】配置实现。

第一步:创建task

由于golang需要先编译再运行,因此我们必须先有一个task将我们的应用编译出来一个可执行文件,等会儿调试时实际上就是调试的这个可执行文件。

创建文件:{项目根目录}/.vscode/tasks.json

在文件中写入内容如下:

{
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "build_debug_version",
            "command": "go",
            "args": [
                "build", "-tags", "dev", "-gcflags", "all=-N -l", "-o", "debug_out.exe"
            ]
        },
        {
            "type": "shell",
            "label": "remove_debug_file",
            "command": "del",
            "args": ["debug_out.exe"]
        }
    ]
}

这里面每个task就相当于一个任务,其中label字段可以当成名称来用。咱们这儿两个任务,build_debug_version 用来编译一个debug版本的可执行文件出来。另一个 remove_debug_file 用来在调试结束后删除debug版本的可执行我呢见。

第二步:添加【运行和调试】配置

创建文件:{项目根目录}/.vscode/launch.json 如果你有这个文件,打开它要编辑一下。

写入如下内容(如果你还有其它内容在你的文件里面,那只需将下面这个数组里面的对象部分粘贴过去就好了):

{
    "configurations": [
        {
            "name": "debug myapp",
            "type": "go",
            "request": "launch",
            "mode": "exec",
            "program": "${workspaceFolder}\\debug_out.exe",
            "preLaunchTask": "build_debug_version",
            "postDebugTask": "remove_debug_file",
            "cwd": "${workspaceFolder}"
        }
    ]
}

第三步:开始调试

先在代码编辑器里,对想要调试的位置打一个断点。然后在vscode的运行和调试面板中,运行我们配置好的 debug myapp 就可以开始调试啦。

Full text complete, Reproduction please indicate the source. Help you? Not as good as one:
Comment(Comments need to be logged in. You are not logged in.)
You need to log in before you can comment.

Comments (0 Comments)