Aaronepower Aaronepower - 14 days ago 5
JSON Question

How to make VS Code build, and run Rust programs?

I've been using VS Code, and I was wondering how build a

task.json
file that will have these commands.
cargo build
,
cargo run [ARGS]
cargo run --release -- [ARGS]


I've tried making one with the documentation on
task.json
. I kept getting
No such subcommand
errors.

Sample:

{
"version": "0.1.0",
// The command is tsc. Assumes that tsc has been installed using npm install -g typescript
"command": "cargo",

// The command is a shell script
"isBuildCommand": true,

// Show the output window only if unrecognized errors occur.
"showOutput": "silent",

"tasks": [{
"taskName": "run test",
"version": "0.1.0",
"command": "run -- --exclude-dir=node_modules C:/Users/Aaron/Documents/Github/",
"isShellCommand": true,
"showOutput": "always"
},
{
"taskName": "run",
"version": "0.1.0",
"args": [ "--"
, "--exclude-dir=node_modules"
, "C:/Users/Aaron/Documents/Github/"
]
"isShellCommand": true,
"showOutput": "always"
}]
}

Answer

The command property is only support top level. In addition arguments have to be passed via the args property. If they are put into the command the command is treated as a command with whitespaces in its name. A example for the run task would look like this:

{
    "version": "0.1.0",
    "command": "cargo",
    "isShellCommand": true, // Only needed if cargo is a .cmd file
    "tasks": [
        {
           "taskName": "run",
           "args": [
               "--release"
               // More args
           ],
           "showOutput": "always"
        }
    ]
}
Comments