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. POJ2421 Constructing Roads【最小生成树】

    题意: 有N个点,有些点已经连接了,然后求出所有点的连接的最短路径是多少. 思路: 最小生成树的变形,有的点已经连接了,就直接把他们的权值赋为0,一样的就做最小生成树. 代码: prime: #inc ...

  2. BZOJ:1816 [Cqoi2010]扑克牌 (贪心或二分答案)

    题面 \(solution:\) 这道题难就难在你能否读懂题目的意思,我们将它翻译一下: 现在我有n根竹子(每根竹子有\(c_i\)节,每节竹子高度为1),我可以通过消耗一点法力值使某一根竹子的某两节 ...

  3. python - isinstance/issubclass 函数

    #isinstance(obj,cls) #检查是否obj是否是object的类cls的对象 #判断一个对象是否是一个类的实例 class F00(object): pass obj = F00() ...

  4. JS的call方法的作用解释,简单易懂

    先看看关于call()的官方解释,“调用一个对象的一个方法,以另一个对象替换当前对象.”,看了这样的解释,或许让你更摸不着头脑了.看例子: var x = "我是全局变量"; // ...

  5. 代码控制打电话、发短信、发邮件、打开手机app等操作

    很多时候我们需要利用我门自己的app进行一些打电话.发短信等的操作,那么如何利用代码实现呢,下面就介绍一些简单的方法来实现这些操作. 一.打电话: <1>最简单.最直接的方法----直接跳 ...

  6. asp.net动态解析用户控件(UserControl)

    模块化的时候需要用到: #region asp.net解析用户控件 /// <summary> /// asp.net 解析用户控件 /// </summary> /// &l ...

  7. tomcat端口冲突,多个tomcat同时启动问题

    一台PC机上安装了两个tomcat,需要同时启动,每个tomcat上跑一个程序,但是现在提示端口号冲突,需要手动更改. 需要修改/conf/server.xml四个地方: 1.<Server p ...

  8. 查看tomcat运行状态

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

  9. Go语言规格说明书 之 结构体类型(Struct types)

    go version go1.11 windows/amd64 本文为阅读Go语言中文官网的规则说明书(https://golang.google.cn/ref/spec)而做的笔记,介绍Go语言的 ...

  10. Win7 x64 svn 服务器搭建

    SVN服务器搭建和使用   Subversion是优秀的版本控制工具,其具体的的优点和详细介绍,这里就不再多说. 首先来下载和搭建SVN服务器. 现在Subversion已经迁移到apache网站上了 ...