When authoring tasks configurations, it is often useful to have a set of predefined common variables. VS Code supports variable substitution inside strings in the tasks.json file and has the following predefined variables:

  • ${workspaceFolder} the path of the workspace folder that contains the tasks.json file
  • ${workspaceRootFolderName} the name of the folder opened in VS Code without any slashes (/)
  • ${file} the current opened file
  • ${relativeFile} the current opened file relative to the workspace folder containing the file
  • ${fileBasename} the current opened file's basename
  • ${fileBasenameNoExtension} the current opened file's basename without the extension
  • ${fileDirname} the current opened file's dirname
  • ${fileExtname} 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 ${env:Path} on Windows.

Below is an example of a custom task configuration that passes the current opened file to the TypeScript compiler.

{
"taskName": "TypeScript compile",
"type": "shell",
"command": "tsc ${file}",
"problemMatcher": [
"$tsc"
]

}

部分翻译:(来自互联网)

${workspaceRoot}
当前打开的文件夹的绝对路径+文件夹的名字

${workspaceRootFolderName}   当前打开的文件夹的名字

${file}当前打开正在编辑的文件名,包括绝对路径,文件名,文件后缀名

${relativeFile}从当前打开的文件夹到当前打开的文件的路径

如 当前打开的是test文件夹,当前的打开的是main.c,并有test / first / second / main.c

那么此变量代表的是  first / second / main.c

${fileBasename} 
当前打开的文件名+后缀名,不包括路径

${fileBasenameNoExtension}
当前打开的文件的文件名,不包括路径和后缀名

${fileDirname}
当前打开的文件所在的绝对路径,不包括文件名

${fileExtname}
当前打开的文件的后缀名

${cwd}
the task runner's current working directory on startup

不知道怎么描述,这是原文解释,


cmd 里面的 cwd 是一样的

${lineNumber} 
当前打开的文件,光标所在的行数

VSCode tasks.json中的各种替换变量的意思 ${workspaceFolder} ${file} ${fileBasename} ${fileDirname}等的更多相关文章

  1. VSCode 在.vscode/launch.json中设置启动时的参数

    如下脚本设置启动参数,如题,在.vscode/launch.json文件中,红色部分设置运行参数 { // Use IntelliSense to learn about possible attri ...

  2. VSCode调试Html中的脚本 vscode前端常用插件推荐,搭建JQuery、Vue等开发环境 vsCode 添加浏览器调试和js调试的方法总结 VS Code - Debugger for Chrome调试js

    一.背景 使用Visual Studio Code写了一个简单的Html页面,想调试下其中script标签里的javascript代码,网上查了一通,基本都是复制粘贴或者大同小异的文章,就是要安装De ...

  3. vscode中关于launch.json和tasks.json的变量说明

    vscode是一个轻量级的文本编辑器,但是它的拓展插件可以让他拓展成功能齐全的IDE,这其中就靠的是tasks.json和launch.json的配置 这两个json文件的相关变量是vscode特有的 ...

  4. 40 VSCode下.json文件的编写——(1) linux/g++ (2).json中参数与预定义变量的意义解释

    0 引言 转入linux/VSCode编程之后,迫切了解到有必有较为系统地学习一下VSCode中相关配置文件的写法.下面将分为 linux/g++编译指令..json文件关键词/替换变量的意义.编译链 ...

  5. vscode中启动浏览器的tasks.json

    {    // See https://go.microsoft.com/fwlink/?LinkId=733558    // for the documentation about the tas ...

  6. 【RMAN】RMAN脚本中使用替换变量

    [RMAN]RMAN脚本中使用替换变量--windows 下rman全备脚本 一.1  BLOG文档结构图 一.2  前言部分 一.2.1  导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也 ...

  7. SQL*Plus中替换变量与定义变量

    替换变量 SQL*Plus中的替换变量又叫替代变量,它一般用来临时存储相关数据:在SQL语句之间传递值.一般使用&或&&前缀来指定替换变量. 关于使用替换变量,一般是利用其创建 ...

  8. 读取Json,并替换json中的指定字符

    string jsonfile = @"E:\history.json";//JSON文件路径 using (System.IO.FileStream file = new Fil ...

  9. js中eval详解,用Js的eval解析JSON中的注意点

    先来说eval的用法,内容比较简单,熟悉的可以跳过eval函数接收一个参数s,如果s不是字符串,则直接返回s.否则执行s语句.如果s语句执行结果是一个值,则返回此值,否则返回undefined. 需要 ...

随机推荐

  1. OOM之类、对象、实例、实体之辨析

    一.场景再现         有一个重要的概念你需要弄明白,那就是“类(class)”和“对象(object)”的区别.我用禅语来解释一下吧:         鱼和三文鱼有什么区别?         ...

  2. 2017-2018-2 20155303 『网络对抗技术』Exp3:免杀原理与实践

    2017-2018-2 20155303 『网络对抗技术』Exp3:免杀原理与实践 --------CONTENTS-------- 1. 免杀原理与实践说明 实验说明 基础问题回答 2. 使用msf ...

  3. 【Ehcache】ehcache2.5.2缓存的使用

    缓存的名字是ehcache...老是记得是encache.... 官方PDF文档:http://www.ehcache.org/documentation/ehcache-2.5.x-document ...

  4. ROS Kinetic Install on Debian 9

    Not Succesed! 1.  配置源$ sudo sh -c 'echo "deb http://packages.ros.org/ros/ubuntu $(lsb_release - ...

  5. CSS在项目中常用的属性总结

    1.媒体查询 2.如何快速生成适配各种浏览器的属性. 3.全面进军移动app开发.

  6. 【转】Python流程控制语句

    [转]Python流程控制语句 人们常说人生就是一个不断做选择题的过程:有的人没得选,只有一条路能走:有的人好一点,可以二选一:有些能力好或者家境好的人,可以有更多的选择:还有一些人在人生的迷茫期会在 ...

  7. nodejs package.json解释

    { "name": "node-echo", # 包名,在NPM服务器上须要保持唯一 "version": "1.0.0" ...

  8. 查看tomcat运行状态

    实时查看tomcat并发连接数: netstat -na | grep ESTAB | grep 8080 | wc -l 实时查看apache并发连接数: netstat -na | grep ES ...

  9. db_recovery_file_dest_size

    select name,space_limit,space_used,number_of_files from v$recovery_file_dest; alter system set db_re ...

  10. 006_ssl监测及评分

    https://testssl.sh/ 一. https://www.ssllabs.com/ssltest/analyze.html?d=jyall.com 监测下jyll.com,不忍直视啊! 二 ...