VSCode:找不到任务中的环境变量 [英] VSCode: Environment variable in task not found

查看:2069
本文介绍了VSCode:找不到任务中的环境变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在VSCode中的task.json中定义自己的环境变量.遵循到目前为止找到的每个链接,我尝试了以下操作:

I am trying to define my own environment variables in the tasks.json in VSCode. Following every link I have found so far, I tried the following:

{
"version": "2.0.0",
"type": "shell",
"options": {
    "env": {
        "APP_NAME": "myApp"
    }
},
"problemMatcher": {
    "owner": "cpp",
    "fileLocation": [
        "relative",
        "${workspaceFolder}"
    ],
    "pattern": {
        "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
        "file": 1,
        "line": 2,
        "column": 3,
        "severity": 4,
        "message": 5
    }
},
"presentation": {
    "echo": true,
    "reveal": "always",
    "focus": false,
    "panel": "dedicated",
    "showReuseMessage": false
},
"tasks": [
    {
        "label": "Build Release",
        "command": "python ./scripts/build_app.py $APP_NAME",
        "group": {
            "kind": "build",
            "isDefault": true
        }
    }
    ]
}

我需要这个,因为我们正在通过python脚本运行构建过程,因此我需要为其指定要构建的应用程序的名称.由于我还具有用于测试,执行,调试等的python脚本,因此我希望只在task.json中更改一次应用程序名称,而不是在每个任务本身中更改一次.

I need this because we are running our build process via a python script and therefore I need to give it the name of the application I want to build. As I am having also python scripts for testing, executing, debugging and so on, I would prefer to change the app name only once in the tasks.json and not in every task itself.

根据指南,这应该可以按照我的方式进行,但是在Powershell控制台中,不会替换$ APP_NAME变量.同样在cmd和bash外壳中,它似乎都不起作用.

According to the guidelines this should be possible in the way I did it, but in the powershell console the $APP_NAME variable is not substituted. Also neither in the cmd nor bash shell it seems to work.

我非常感谢别人能给我任何帮助.

I would be very grateful for any help someone could give me.

推荐答案

在您的情况下使用$env:APP_NAME.请参见引用环境变量.

Use$env:APP_NAME in your case. See referencing environment variables.

环境变量

您还可以通过${env:Name}引用环境变量 语法(例如${env:PATH}).

You can also reference environment variables through ${env:Name} syntax (for example, ${env:PATH}).

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

注意:请确保匹配环境变量名称的大小写,例如 例如Windows上的${env:Path}.

Note: Be sure to match the environment variable name's casing, for example ${env:Path} on Windows.

这篇关于VSCode:找不到任务中的环境变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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