visual-studio-code - Visual Studio Code 任务正在将工作目录添加到命令中

标签 visual-studio-code rust

我正在尝试为 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/

相关文章:

rust - 变量在嵌套 lambda 中存活时间不够长的借用检查错误

visual-studio-code - 在VScode中打开搜索结果中存在的所有文件

angular - 如何在 typescript/angular 中设置子 html 元素的样式

performance - 为什么XOR比OR快得多?

c - 从 `std::io::File::open` 获取文件描述符

arrays - 创建多个不同但固定大小的数组

python - VS code 不会检查我的代码,但内部构建会检查我的代码

git - Visual Studio Code - git 颜色和项目层次结构

visual-studio-code - 在 Visual Studio Code 中增加 Bokeh 图的单元格大小

rust - 如何借用对 Option<T> 中内容的引用?