我正在尝试为 Rust 设置 visual studio 代码以进行调试。在我的 launch.json 文件中有
{
"version": "0.2.0",
"configurations": [
{
"name": "(Windows) Launch",
"type": "cppvsdbg",
"request": "launch",
"program": "${workspaceRoot}/target/debug/vscode-rust-debug-example.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"preLaunchTask": "localcargobuildtask"
}
]
}
在我的 tasks.json 中有
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "localcargobuildtask",
"command": "echo hi",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
在我的任务中出现“echo hi”的地方,我最终想要的是“cargo build”或“cargo test”之类的东西。但这只是一个开始。
但是当我按 F5 时,我得到的输出是
> Executing task: C:\programs\VSCodeWorkspaces\RustProjects\vscode-rust-debug-example-debug-config-included\echo hi <
The terminal process terminated with exit code: 2
Terminal will be reused by tasks, press any key to close it.
它不是从终端找到它的地方运行“echo”(首先是工作目录,然后像你期望的那样检查全局路径变量)它实际上是在我的工作区的根文件夹中寻找一个名为“echo”的程序。
我如何告诉 visual studio 代码“不,我不想让你运行工作空间/echo,我想让你在工作空间中运行 echo”?或者是否有另一种更直接的方式告诉 visual studio 代码“在调试之前编译它”?
最佳答案
这个问题的答案How to debug Rust unit tests on Windows? 建议改变
"command": "cargo build",
进入
"command": "cargo",
"args": [
"build"
],
在 tasks.json 文件中有效,并且以某种方式起作用。也许编辑器配置为在 %path% 中搜索单个单词命令,或者我安装的某些插件覆盖了“cargo”命令。也许找不到 echo 的原因是因为它是一个终端命令,而不是程序。也许错误消息是一个谎言,它只是报告说尽管检查了 %path% 但它找不到 workspacefolder\command?或者也许都不是。我不知道。这是一些非常特殊的行为。
关于visual-studio-code - Visual Studio Code 任务正在将工作目录添加到命令中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56159436/