温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

VSCode launch.json中的各种替换变量指的是什么意思

发布时间:2021-02-22 13:06:39 来源:亿速云 阅读:467 作者:清风 栏目:编程语言

本文将为大家详细介绍“VSCode launch.json中的各种替换变量指的是什么意思”,内容步骤清晰详细,细节处理妥当,而小编每天都会更新不同的知识点,希望这篇“VSCode launch.json中的各种替换变量指的是什么意思”能够给你意想不到的收获,请大家跟着小编的思路慢慢深入,具体内容如下,一起去收获新知识吧。

vscode有什么用

Visual Studio Code 是一个运行于 OS X,Windows和 Linux 之上的,针对于编写现代 web 和云应用的跨平台编辑器,它为开发者们提供了对多种编程语言的内置支持,并且正如 Microsoft 在Build 大会的 keynote 中所指出的,这款编辑器也会为这些语言都提供了丰富的代码补全和导航功能。

VS Code supports variable substitution inside strings in launch.json and has the following predefined variables:

  • ${workspaceFolder} - the path of the folder opened in VS Code

  • ${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 workspaceRoot

  • ${fileBasename} - the current opened file's basename

  • ${fileBasenameNoExtension} - the current opened file's basename with no file 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} syntax (for example, ${env:PATH}). Be sure to match the environment variable name's casing, for example ${env:Path} on Windows.

{
 "type": "node",
 "request": "launch",
 "name": "Launch Program",
 "program": "${workspaceFolder}/app.js",
 "cwd": "${workspaceFolder}",
 "args": [ "${env:USERNAME}" ]
}

You can reference VS Code settings and commands using the following syntax:

  • ${config:Name} - example: ${config:editor.fontSize}

  • ${command:CommandID} - example: ${command:explorer.newFolder}

在vscode中定义了一些变量,在配置任务脚本时,可能会用到。本文以launch.json脚本为例,介绍各个变量的含义。

假设当前workspace的路径为:"C:\Users\admin\Desktop\test",workspace文件夹下的结构如下(+表示下一层):

C:\Users\admin\Desktop\test

+.vscode

  ++tasks.json

  ++launch.json

+main.cpp

${workspaceFolder} :表示当前workspace文件夹路径,也即C:\Users\admin\Desktop\test

${workspaceRootFolderName}:表示workspace的文件夹名,也即test

${file}:文件自身的绝对路径,也即C:\Users\admin\Desktop\test\.vscode\launch.json

${relativeFile}:文件在workspace中的路径,也即.vscode\launch.json

${fileBasenameNoExtension}:当前文件的文件名,不带后缀,也即launch

${fileBasename}:当前文件的文件名,launch.json

${fileDirname}:文件所在的文件夹路径,也即C:\Users\admin\Desktop\test\.vscode

${fileExtname}:当前文件的后缀,也即.json

${lineNumber}:当前文件光标所在的行号

${env:PATH}:系统中的环境变量

如果你能读到这里,小编希望你对“VSCode launch.json中的各种替换变量指的是什么意思”这一关键问题有了从实践层面最深刻的体会,具体使用情况还需要大家自己动手实践使用过才能领会,如果想阅读更多相关内容的文章,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI