本文介绍了如何在 VSCode 中将环境变量添加到 launch.json的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 node.js 项目上使用新的 VSCode 编辑器.我正在尝试通过编辑 launch.json 文件来配置我的启动"配置文件以进行调试.我需要将连接字符串设置为环境变量.根据launch.json文件中的注释:

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 connectionstring as an environment variable. According to the comments in the launch.json file:

// Environment variables passed to the program.
"env": { }

我试过像这样添加我的环境变量:

I have tried adding my environment variable like so:

"env":
{
"CONNECTION_STRING": "Data Source=server;Initial Catalog=catalog;User ID=uid;Password=pwd;MultipleActiveResultSets=true"
}

当我尝试启动我的应用程序时,这会导致错误;OpenDebug 进程意外终止".我还没有找到任何可以解释问题所在的日志文件等.

This causes an error when I try to launch my app; "OpenDebug process has terminated unexpectedly". I have not yet found any log files, etc. that might explain what the issue is.

当我设置环境变量并从标准命令提示符启动我的应用程序时,我知道这个应用程序可以正常工作.如果我在 launch.json 文件中注释掉我的变量,应用程序也会按预期运行;我就是无法连接到数据库.

I know this app works correctly when I setup the environment variable and launch my app from the standard command prompt. The app also runs as expected if I comment out my variable in the launch.json file; I just can't connect to the database.

我假设我在 launch.json 文件中使用了错误的格式,但我还没有找到任何方法来完成这项工作.

I am assuming that I am using the wrong format in the launch.json file, but I have not yet found any way to make this work.

有什么想法吗?

推荐答案

Windows(也可能是 linux)上的环境变量似乎存在问题.它确实适用于 OS X.我们正在调查.期待尽快修复.

There seems to be a problem with environment variables on Windows (and probably on linux). It does work on OS X. We are investigating. Expect a fix soon.

更新(2015 年 6 月 2 日):Visual Studio Code 0.3.0 包含对此的修复.

Update (June 2, 2015): Visual Studio Code 0.3.0 contains a fix for this.

这篇关于如何在 VSCode 中将环境变量添加到 launch.json的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-24 12:12