VScode远程开发:在运行实际的构建任务之前,如何运行构建任务以获取环境变量?

问题描述 投票:0回答:1

我想设置VScode,以便可以使用构建任务来构建我的项目。该项目是使用make构建的,我已定义了运行make的构建任务。但是,在运行make之前,我通常会提供一个可以正确设置环境变量的脚本。如果我使用source命令添加新的构建任务,并将主要构建任务设置为首先执行source命令,则不会正确传播环境变量。如何确保在构建任务之间保留环境变量?

我的tasks.json文件:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558 
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "type": "shell",
            "label": "make",
            "command": "make",
            "args": [],
            "problemMatcher": [
                "$gcc"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "dependsOn": "Set environment"
        },
        {
            "label": "Set environment",
            "type": "shell",
            "command": "source path/to/source_me.sh",
            "group": "build",
   ]
}
visual-studio-code environment-variables gnu-make
1个回答
0
投票

不是这样。采购文件会将文件内容注入当前的Shell会话中,该会话在任务结束后立即终止。 make任务在单独的Shell会话中运行,因此这两个不交互。您可以尝试执行一个执行单行的任务:source path/to/source_me.sh && make

© www.soinside.com 2019 - 2024. All rights reserved.