在 VS Code 中调试
本指南将引导你设置 VS Code 以调试 Tauri 应用的核心流程。
¥This guide will walk you through setting up VS Code for debugging the Core Process of your Tauri app.
所有带有 vscode-lldb 扩展的平台
¥All platforms with vscode-lldb extension
先决条件
¥Prerequisites
安装 vscode-lldb
扩展。
¥Install the vscode-lldb
extension.
配置 launch.json
¥Configure launch.json
创建一个 .vscode/launch.json
文件并将以下 JSON 内容粘贴到其中:
¥Create a .vscode/launch.json
file and paste the below JSON contents into it:
{ // 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": [ { "type": "lldb", "request": "launch", "name": "Tauri Development Debug", "cargo": { "args": [ "build", "--manifest-path=./src-tauri/Cargo.toml", "--no-default-features" ] }, // task for the `beforeDevCommand` if used, must be configured in `.vscode/tasks.json` "preLaunchTask": "ui:dev" }, { "type": "lldb", "request": "launch", "name": "Tauri Production Debug", "cargo": { "args": ["build", "--release", "--manifest-path=./src-tauri/Cargo.toml"] }, // task for the `beforeBuildCommand` if used, must be configured in `.vscode/tasks.json` "preLaunchTask": "ui:build" } ]}
这将直接使用 cargo
来构建 Rust 应用并在开发和生产模式下加载它。
¥This uses cargo
directly to build the Rust application and load it in both development and production modes.
请注意,它不使用 Tauri CLI,因此不会执行独有的 CLI 功能。beforeDevCommand
和 beforeBuildCommand
脚本必须事先执行或在 preLaunchTask
字段中配置为任务。下面是一个示例 .vscode/tasks.json
文件,它有两个任务,一个用于生成开发服务器的 beforeDevCommand
,另一个用于 beforeBuildCommand
:
¥Note that it does not use the Tauri CLI, so exclusive CLI features are not executed. The beforeDevCommand
and beforeBuildCommand
scripts must be executed beforehand or configured as a task in the preLaunchTask
field. Below is an example .vscode/tasks.json
file that has two tasks, one for a beforeDevCommand
that spawns a development server and one for beforeBuildCommand
:
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "ui:dev", "type": "shell", // `dev` keeps running in the background // ideally you should also configure a `problemMatcher` // see https://code.visualstudio.com/docs/editor/tasks#_can-a-background-task-be-used-as-a-prelaunchtask-in-launchjson "isBackground": true, // change this to your `beforeDevCommand`: "command": "yarn", "args": ["dev"] }, { "label": "ui:build", "type": "shell", // change this to your `beforeBuildCommand`: "command": "yarn", "args": ["build"] } ]}
现在你可以在 src-tauri/src/main.rs
或任何其他 Rust 文件中设置断点,然后按 F5
开始调试。
¥Now you can set breakpoints in src-tauri/src/main.rs
or any other Rust file and start debugging by pressing F5
.
在 Windows 上使用 Visual Studio Windows 调试器
¥With Visual Studio Windows Debugger on Windows
Visual Studio Windows Debugger 是一款仅适用于 Windows 的调试器,通常比 vscode-lldb
更快,并且更好地支持某些 Rust 功能(例如枚举)。
¥Visual Studio Windows Debugger is a Windows-only debugger that is generally faster than vscode-lldb
with better support for some Rust features such as enums.
先决条件
¥Prerequisites
安装 C/C++ 扩展并按照 https://code.visualstudio.com/docs/cpp/config-msvc#_prerequisites 安装 Visual Studio Windows 调试器。
¥Install the C/C++ extension and follow https://code.visualstudio.com/docs/cpp/config-msvc#_prerequisites to install Visual Studio Windows Debugger.
配置 launch.json 和 task.json
¥Configure launch.json and tasks.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 App Debug", "type": "cppvsdbg", "request": "launch", // change the exe name to your actual exe name // (to debug release builds, change `target/debug` to `release/debug`) "program": "${workspaceRoot}/src-tauri/target/debug/your-app-name-here.exe", "cwd": "${workspaceRoot}", "preLaunchTask": "ui:dev" } ]}
请注意,它不使用 Tauri CLI,因此不会执行独有的 CLI 功能。tasks.json
与 lldb
相同,但如果你希望它在启动前始终进行编译,则需要添加一个配置组并将 preLaunchTask
从 launch.json
定位到它。
¥Note that it does not use the Tauri CLI, so exclusive CLI features are not executed. The tasks.json
is the same as with lldb
, except you need to add a config group and target your preLaunchTask
from launch.json
to it if you want it to always compile before launching.
以下是将开发服务器(相当于 beforeDevCommand
)和编译(cargo build
)作为一个组运行的示例,要使用它,请将 launch.json
中的 preLaunchTask
配置更改为 dev
(或你为组命名的任何名称)。
¥Here is an example of running a dev server (equivalent of beforeDevCommand
) and the compilation (cargo build
) as a group, to use it, change the preLaunchTask
config in launch.json
to dev
(or anything you named your group).
{ // See https://go.microsoft.com/fwlink/?LinkId=733558 // for the documentation about the tasks.json format "version": "2.0.0", "tasks": [ { "label": "build:debug", "type": "cargo", "command": "build" }, { "label": "ui:dev", "type": "shell", // `dev` keeps running in the background // ideally you should also configure a `problemMatcher` // see https://code.visualstudio.com/docs/editor/tasks#_can-a-background-task-be-used-as-a-prelaunchtask-in-launchjson "isBackground": true, // change this to your `beforeDevCommand`: "command": "yarn", "args": ["dev"] }, { "label": "dev", "dependsOn": ["build:debug", "ui:dev"], "group": { "kind": "build" } } ]}
Tauri 中文网 - 粤ICP备13048890号