How do I add environment variables to launch.json in VSCode

前端 未结 10 794
囚心锁ツ
囚心锁ツ 2020-12-08 01:29

Working with the new VSCode editor on a node.js project. I am attempting to configure my \"Launch\" profile for debugging by editing the launch.json file. I need to setup a

10条回答
  •  南方客
    南方客 (楼主)
    2020-12-08 02:04

    as a workaround, you can set environment variables when starting VSCode, for example, using this little powershell script:

    param(
     $vars = @{}
    )
    
    $vars.Keys | % {
        write-host "adding env variable: $_=$($vars[$_])"
        [Environment]::SetEnvironmentVariable($_, $vars[$_], "Process")
    }
    $ver = "0.1.0"
    & "$env:LOCALAPPDATA\Code\app-$ver\Code.exe"
    

    Save it as vscode.ps1 and call it from commandline, like this:

    powershell ".\vscode.ps1 -vars @{ 'NODE_ENV'='test'; 'SOMETHING'='else' }"
    

提交回复
热议问题