VSCode tasks.json中pickFile输出路径转换问题求助
解决方案
修改你的tasks.json配置,通过extension.commandvariable.transform对选中的文件路径进行正则替换,提取出你需要的文件名部分:
{ "version": "2.0.0", "tasks": [ { "label": "build", "type": "shell", "command": "${userHome}/build.py", "args": ["param_def=${input:pickBuild}"] } ], "inputs": [ { "id": "pickBuild", "type": "command", "command": "extension.commandvariable.transform", "args": { "command": "extension.commandvariable.file.pickFile", "args": { "include": "**/default_*.py", "description": "Select build", "display": "fileName" }, "transform": { "find": "^.*\\/(default_.*)\\.py$", "replace": "$1" } } } ] }
关键说明
- 外层使用
extension.commandvariable.transform作为输入命令,嵌套调用file.pickFile获取选中的文件路径 transform配置里的正则表达式^.*\/(default_.*)\.py$会匹配完整文件路径,捕获default_开头到.py之前的部分- 替换为
$1即可得到你需要的default_android格式的字符串
这样执行build任务时,生成的命令就会是你期望的:/home/user/build.py param_def=default_android
内容的提问来源于stack exchange,提问作者FelX3
相关产品推荐
相关产品推荐

