Visual Studio Code, as an IDE, executes Python programs in real time and plays a big role in debugging or understanding execution steps! Therefore, the following to make a simple acceptance, I hope the vast number of park friends to put forward valuable advice!
1. Official notes
Http://code.visualstudio.com/docs/editor/tasks
2. Configure the execution Environment
Note: Please note that the task support was only available when working on a workspace folder. It isn't available when editing single files.
2.1 Configuring Task.json
A. Creating a workspace folder
B. Tasks:configure task Runner (Configuration execution Tasks), ctrl+shift+p , Task
C. Click "Configure task Run Program" to pop up the window
Output Window behavior#
Sometimes you'll want to control how the output window behaves when running tasks. For instance, the want to maximize editor space and the only look at task output if you think there are a problem. The property showoutput controls This and the valid values is:
- always-the output window was always brought to front. This is the default.
- never -the user must explicitly bring the output window to the front using the View > Toggle out Put command (ctrl+shift+u).
- Silent -The Output window is brought to front only if no problem matchers be set for the task.
Command and tasks[]#
tasks.jsonTakes a singlecommandvalue which can is a task runner like Gulp or grunt or any command line tool like a compiler or linte R. By default the'll show up in thecommandtasks:run Taskdropdown.
You can also define multiple tasks in atasksarray in order to pass different arguments or use different settings when th E iscommandrun.
Here's a simple example passing different arguments to theechocommand:
1 {
2 "version": "0.1.0",
3 "command": "echo",
4 "isShellCommand": true,
5 "args": [],
6 "showOutput": "always",
7 "echoCommand": true,
8 "suppressTaskName": true,
9 "tasks": [
10 {
11 "taskName": "hello",
12 "args": ["Hello World"]
13 },
14 {
15 "taskName": "bye",
16 "args": ["Good Bye"]
17 }
18 ]
19 }
Sometasks.jsonproperties such asshowOutputandsuppressTaskNamecan is set both globally and then overridden in specific tasks. The property values is appended to thetasksargsglobal arguments.
There is alsotasksspecific properties. One useful propertyisBuildCommandwas, which if set to true, would run the task with the Tasks:run Build task (ctrl+sh ift+b) command.
Running multiple commands#
What if the want to run different command line tools in your workspace? Defining multiple tasks in are nottasks.jsonyet fully supported by VS Code (see #981). You can work around the limitation by running your task commands through a shell command (onshLinux and Mac,cmdo n Windows).
Here is a example to add the tasks formakeandls:
1 {
2 "version": "0.1.0",
3 "command": "sh",
4 "args": ["-c"],
5 "isShellCommand": true,
6 "showOutput": "always",
7 "suppressTaskName": true,
8 "tasks": [
9 {
10 "taskName": "make",
11 "args": ["make"]
12 },
13 {
14 "taskName": "ls",
15 "args": ["ls"]
16 }
17 ]
18 }
Both tasks and would be visible in themakelstasks:run Task dropdown.
For Windows, you'll need to pass the '/C ' argument to So, thecmdtasks arguments is run.
"command": "cmd",
"args": ["/C"]
Variable substitution#
When authoring tasks configurations, it was often useful to has a set of predefined common variables. VS Code supports variable substitution inside strings in the file and have thetasks.jsonfollowing predefined variables:
- ${workspaceroot} The path of the folder opened in VS Code
- ${workspacerootfoldername} the name of the folder opened in VS Code without any solidus (/)
- ${file} the current opened file
- ${relativefile} The current opened file relative toworkspaceRoot
- ${filebasename} The current opened file ' s basename
- ${filedirname} The current opened file ' s dirname
- ${fileextname} The current opened file ' s extension
- ${CWD} The task runner ' s current working directory on startup
You can also reference environment variables through ${env. Name} (e.g. ${env. PATH}). Be sure to match the environment variable name ' s casing, for example onenv.PathWindows.
Below is an example of a configuration, that passes, opened file to the TypeScript compiler.
1 {
2 "command": "tsc",
3 "args": ["${file}"]
4 }
Operating System Specific properties#
The task system supports defining values (for example, the command to being executed) specific to an operating system. To doing so, simply put a operating system specific literal into thetasks.jsonfile and specify the corresponding properties Insi De that literal.
Below is an example that uses the node. JS executable as a command and is treated differently on Windows and Linux:
1 {
2 "version": "0.1.0",
3 "windows": {
4 "command": "C:\\Program Files\\nodejs\\node.exe"
5 },
6 "linux": {
7 "command": "/usr/bin/node"
8 }
9 }
Valid Operating Propertieswindowsis for Windows, for Linux and forlinuxosxMac. Properties defined in a operating system specific scope override properties defined in the global scope.
In the example below:
1 {
2 "version": "0.1.0",
3 "showOutput": "never",
4 "windows": {
5 "showOutput": "always"
6 }
7 }
8 Output from the executed task is never brought to front except for Windows where it is always shown.
[Visual Studio Code] executes python