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 the tasks.json
following predefined variables:
- ${workspacefolder} the Path of the workspace folder that contains the Tasks.json file
- ${workspace Rootfoldername} the name of the folder opened in VS Code without a slashes (/)
- ${file} the current O pened file
- ${relativefile} the current opened file relative to the workspace folder containing the File
- ${filebasename} the opened file ' s basename
- ${filebasenamenoextension} the Current Opened file ' s basename without the extension
- ${filedirname} the current opened file ' s dirname
- ${f Ileextname} the current opened file ' s extension
- ${cwd} the task Runner ' s current working directory on Startup
- ${linenumber} the Current selected line number in the active file
You can also reference environment variables through ${env:name} (for example, ${env:path}). Be sure to match the environment variable name ' s casing, for example on ${env:Path}
Windows.
Below is an example of a custom task configuration this passes the current opened file to the TypeScript compiler.
{ "taskName": "TypeScript compile", "type": "shell", "command": "tsc ${file}", "problemMatcher": [ "$tsc" ]
}
Partial translation: (from the Internet)
${workspaceroot} The absolute path of the folder currently open + the name of the folder
${workspacerootfoldername} The name of the folder that is currently open
${file} currently open the file name you are editing, including absolute path, filename, file suffix name
${relativefile} from the currently open folder to the path of the currently open file
As currently open is the Test folder, the current open is MAIN.C, and has TEST/FIRST/SECOND/MAIN.C
Then this variable represents the FIRST/SECOND/MAIN.C
${filebasename} The currently open file name + suffix name, excluding path
${filebasenamenoextension} file name of the currently open file, excluding path and suffix names
${filedirname} The absolute path of the currently open file, excluding file name
${fileextname} The suffix name of the currently open file
${CWD} The Task runner ' s current working directory on startup
Do not know how to describe, this is the original explanation,
It's the same as the CWD in CMD.
${linenumber} The currently open file, the number of lines where the cursor is located
Vscode Tasks.json The meaning of the various substitution variables ${workspacefolder} ${file} ${filebasename} ${filedirname}, etc.