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:
在节点上使用新的VSCode编辑器。js的项目。我正在尝试通过编辑启动来配置我的“启动”配置文件以进行调试。json文件。我需要将connectionstring设置为环境变量。根据发布会上的评论。json文件:
// 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"
}
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.
当我试图启动我的应用程序时,这会导致一个错误;“OpenDebug进程已意外终止”。我还没有找到任何可能解释问题的日志文件等等。
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.
当我安装环境变量并从标准命令提示符启动我的应用程序时,我知道这个应用程序可以正常工作。如果我在发布中注释掉我的变量,应用程序也会按预期运行。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.
我假设我在发射中使用了错误的格式。json文件,但是我还没有找到任何方法来完成这个工作。
Any ideas?
什么好主意吗?
4 个解决方案
#1
5
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.
Windows上的环境变量似乎存在问题(可能在linux上也是如此)。它在OS x上工作,我们正在调查。希望尽快修复。
Andre Weinand, Visual Studio Code
Andre Weinand, Visual Studio代码
#2
6
I'm successfully passing them using the env
property in launch.json
:
我正在使用启动中的env属性成功地传递它们。
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "SLS Webpack",
"protocol": "legacy",
"program": "${workspaceRoot}/node_modules/.bin/sls",
"cwd": "${workspaceRoot}",
"args": ["webpack", "watch", "-f", "${fileBasenameNoExtension}", "-p", "${fileDirname}/event.json"],
"env": {"AWS_REGION":"us-east-1", "SLS_DEBUG":"*"},
"outFiles": ["${cwd}/dist/**/*.js"],
"sourceMaps": true,
"smartStep": true
}
]
}
#3
2
as a workaround, you can set environment variables when starting VSCode, for example, using this little powershell script:
作为一个解决方案,您可以在启动VSCode时设置环境变量,例如,使用这个小小的powershell脚本:
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:
vscode保存它。从命令行调用它,如下所示:
powershell ".\vscode.ps1 -vars @{ 'NODE_ENV'='test'; 'SOMETHING'='else' }"
#4
0
Like this, under you OS:
像这样,在你的下面:
"osx": {
"MIMode": "lldb",
"environment": [{"name": "DYLD_LIBRATY_PATH", "value": "/Users/x/boost_1_63_0/stage/lib/"}]
},
#1
5
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.
Windows上的环境变量似乎存在问题(可能在linux上也是如此)。它在OS x上工作,我们正在调查。希望尽快修复。
Andre Weinand, Visual Studio Code
Andre Weinand, Visual Studio代码
#2
6
I'm successfully passing them using the env
property in launch.json
:
我正在使用启动中的env属性成功地传递它们。
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "SLS Webpack",
"protocol": "legacy",
"program": "${workspaceRoot}/node_modules/.bin/sls",
"cwd": "${workspaceRoot}",
"args": ["webpack", "watch", "-f", "${fileBasenameNoExtension}", "-p", "${fileDirname}/event.json"],
"env": {"AWS_REGION":"us-east-1", "SLS_DEBUG":"*"},
"outFiles": ["${cwd}/dist/**/*.js"],
"sourceMaps": true,
"smartStep": true
}
]
}
#3
2
as a workaround, you can set environment variables when starting VSCode, for example, using this little powershell script:
作为一个解决方案,您可以在启动VSCode时设置环境变量,例如,使用这个小小的powershell脚本:
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:
vscode保存它。从命令行调用它,如下所示:
powershell ".\vscode.ps1 -vars @{ 'NODE_ENV'='test'; 'SOMETHING'='else' }"
#4
0
Like this, under you OS:
像这样,在你的下面:
"osx": {
"MIMode": "lldb",
"environment": [{"name": "DYLD_LIBRATY_PATH", "value": "/Users/x/boost_1_63_0/stage/lib/"}]
},