Vscode Tasks.json The meaning of various substitution variables ${workspacefolder} ${file} ${filebasename} ${filedirname}, etc.

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.