Skip to content

[bug] launch.json envFile not capable of variable interpolation #13781

Description

Environment

  • OS and version: Windows NT x64 10.0.19045
  • VS Code: 1.99.1
  • C/C++ extension:
  • OS and version of remote machine (if applicable): N/A
  • GDB / LLDB version: N/A

Bug Summary and Steps to Reproduce

Bug Summary:
.env files don't appropriately handle variable substitution in conformance with the dotenv file spec

Initially raised as microsoft/vscode#257570 but advised to move the issue here.
Relates to #9329

Steps to Reproduce:

  1. Create a blank repo and populate it with the following files:
    • launch.json
    {
        "version": "0.2.0",
        "configurations": [
            {
                "name": "(msvc) Launch",
                "type": "cppvsdbg",
                "request": "launch",
                "stopAtEntry": false,
                "cwd": "${workspaceFolder}",
                "environment": [],
                "envFile": "${workspaceFolder}/.env"
            }
        ]
    }
    • .env
    USER=admin
    EMAIL=${USER}@example.org
    PATH=~/project:${PATH}
    
  2. Press F5 to trigger launch.json
  3. Observe the following error message:

Invalid variable reference ${USER} in string: ${USER}@example.org.
Invalid variable reference ${PATH} in string: ~/project:${PATH}.

Expected behaviour

  • USER=admin is exported to the environment
  • EMAIL=admin@example.org is exported to the environment
  • PATH=/home/username/project:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin (or some approximation thereof) is exported to the environment

Which would be consistent with Interpolation/Variable Substitution in dotenv files

Context

I'm trying to identify a transparent integration with conan for C++ development. One of the considerations for this is being able to update the following environment variables to allow the debugger to correctly resolve the paths to dependent libraries:

  • LD_LIBRARY_PATH
  • DYLD_LIBRARY_PATH
  • PATH

Conan achieves this currently (unrelated to VSCode) by generating a conanrun.{sh,bat,ps1} set of files that updates the environment. The idea is that one does the following:

source build/Debug/generators/conanrun.sh
cmake --presets conan-release
cmake --build conan-release

It doesn't seem like VSCode has the ability to do the first part of this with the existing file formats as part of its application launch cycle. conan-io/conan#11042 proposes the addition of an ability to generate a conanrun.env, which could be consumed by the envFile parameter. However, as discussed in conan-io/conan#11042 (comment) and conan-io/conan#11042 (comment), the syntax/features that VSCode expects/supports seems inconsistent to what is understood to be the dotenv file schema

Debugger Configurations

Above

Debugger Logs

Above

Other Extensions

Persists after disabling all other extensions.

Additional Information

No response

Activity

  1. changed the title [-]launch.json envFile not capable of variable interpolation[/-] [+][bug] launch.json envFile not capable of variable interpolation[/+] on Jul 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bughelp wantedCan be fixed in the public (open source) repo.tasks/build/debugAn issue relating to tasks.json (e.g. build issues)

    Type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions