VSCode tasks.json中的各种替换变量的意思 ${workspaceFolder} ${file} ${fileBasename} ${fileDirname}等

 

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}  当前打开的文件,光标所在的行数

 

更新一个链接:https://code.visualstudio.com/docs/editor/variables-reference

 

 

  • 7
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
好的,我来回答你的问题。 首先,你需要在Windows上安装OpenCV。你可以通过以下步骤来完成: 1. 下载OpenCV的Windows版本,可以从官网下载,也可以从GitHub上下载。 2. 解压下载好的压缩包。 3. 将解压后的文件夹复制到某个目录下,比如 C:\OpenCV。 4. 将OpenCV的bin目录添加到系统环境变量。具体方法是:在Windows搜索栏输入“环境变量”,然后点击“编辑系统环境变量”,在弹出的窗口点击“环境变量”,在“系统变量找到“Path”并双击打开,然后点击“新建”添加OpenCV的bin目录,比如 C:\OpenCV\bin。 5. 验证OpenCV是否成功安装。可以在命令行输入“opencv_version”命令来查看OpenCV的版本号。 接下来,你需要配置vscodetasks.json文件。tasks.json文件是一个用于配置任务(Task)的文件,可以用于编译、运行程序等操作。下面是配置tasks.json文件的步骤: 1. 在vscode打开你的项目。 2. 在菜单栏选择“终端(Terminal)” -> “新建终端(New Terminal)”。 3. 在终端输入以下命令来创建tasks.json文件: ``` code .\tasks.json ``` 4. 在打开的tasks.json文件输入以下配置信息: ``` { "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "g++", "args": [ "-g", "your_source_file.cpp", "-o", "your_executable_file.exe", "-I", "C:/OpenCV/include", "-L", "C:/OpenCV/lib", "-lopencv_core", "-lopencv_highgui", "-lopencv_imgproc", "-lopencv_imgcodecs" ], "group": { "kind": "build", "isDefault": true } } ] } ``` 其,label表示任务的名称,command和args表示编译命令及其参数,group表示任务的分组信息。需要根据自己的文件名和路径进行修改。 5. 保存tasks.json文件,并在vscode的菜单栏选择“任务(Tasks)” -> “运行任务(Run Task)” -> “build”来编译程序。 这样就可以配置好vscodetasks.json文件了。希望对你有所帮助。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值