Visual Studio Code 中 launch.json 的通用变量 [英] Common variables for launch.json in Visual Studio Code

查看:53
本文介绍了Visual Studio Code 中 launch.json 的通用变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到 Visual Studio Code 的 launch.json 如何访问 ${workspaceFolder}.它是否也可以访问其他公共变量?我想访问当前用户的 AppData 文件夹,以便我可以这样做:

I have seen how launch.json for Visual Studio Code has access to ${workspaceFolder}. Does it also have access to other common variables? I would like to have access to the current user's AppData folder so I can do:

"program": "${appData}\\Roaming\\npm\\node_modules\\gulp\\bin\\gulp.js"

而不是将其硬编码为:

"program": "C:\\Users\\jdoe\\AppData\\Roaming\\npm\\node_modules\\gulp\\bin\\gulp.js"

推荐答案

launch.json 中的变量替换支持环境变量.对于您的用例,您可以使用 ${env:AppData}.

Variable substitution in launch.json supports environment variables. For your use-case you can use ${env:AppData}.

VS Code 支持 launch.json 中字符串内的变量替换,与 tasks.json 相同.

VS Code supports variable substitution inside strings in launch.json the same way as for tasks.json.

https://code.visualstudio.com/docs/editor/tasks#_变量替换

  • ${workspaceFolder} VS Code 中打开的文件夹路径
  • ${file} 当前打开的文件
  • ${relativeFile} 当前打开的文件相对于workspaceRoot
  • ${fileBasename} 当前打开文件的基名
  • ${fileDirname} 当前打开文件的目录名
  • ${fileExtname} 当前打开文件的扩展名
  • ${cwd} 启动时任务运行器的当前工作目录
  • ${workspaceFolder} the path of the folder opened in VS Code
  • ${file} the current opened file
  • ${relativeFile} the current opened file relative to workspaceRoot
  • ${fileBasename} the current opened file's basename
  • ${fileDirname} the current opened file's dirname
  • ${fileExtname} the current opened file's extension
  • ${cwd} the task runner's current working directory on startup

您还可以通过 ${env:Name} 引用环境变量(例如${env:PATH}).确保匹配环境变量名称的大小写,例如 env:Path 在 Windows 上.

You can also reference environment variables through ${env:Name} (e.g. ${env:PATH}). Be sure to match the environment variable name's casing, for example env:Path on Windows.

这篇关于Visual Studio Code 中 launch.json 的通用变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆