Visual Studio代码任务将工作目录预先到命令



我正在尝试设置Rust的Visual Studio代码进行调试。在我的启动中,我有

{
    "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"
        }
    ]
}

和我的任务中。

{
    // 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"的位置我最终想拥有"货物构建"或"货物测试"之类的东西。但这只是一个开始步骤。

,但是当我按F5时,我将获得的输出是

> Executing task: C:programsVSCodeWorkspacesRustProjectsvscode-rust-debug-example-debug-config-includedecho 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?还是还有另一种直接的方法来告诉Visual Studio代码"在调试之前对此进行编译"?

这个问题的答案如何在Windows上调试Rust单元测试?建议更改

"command": "cargo build",

进入

"command": "cargo",
    "args": [
        "build"
    ],

tasks.json文件有效,并且以某种方式可以。也许编辑器被配置为搜索%路径%以查看单词命令,或者我安装的一些插件覆盖了"货物"命令。也许没有找到回声的原因是因为它是终端命令,而不是程序。也许错误消息是一个谎言,它只是报告说尽管检查%路径%,但它还是找不到WorkspaceFolder 命令?也许没有。我不知道。这是一些漂亮的特殊行为。

最新更新