您能帮我,如何在Visual Studio代码中设置环境变量?
您能帮我,如何在Visual Studio代码中设置环境变量?
Answers:
假设您要进行调试会话(?),则可以env
在启动配置中包含一个属性。
如果您在工作区中打开.vscode / launch.json文件,或选择“调试”>“打开配置”,则应该看到一组用于调试代码的启动配置。然后,可以向其添加一个env
带有string:string字典的属性。
这是一个ASP.NET Core应用程序的示例,其标准Web模板将设置ASPNETCORE_ENVIRONMENT
为Development
:
{
"version": "0.2.0",
"configurations": [
{
"name": ".NET Core Launch (web)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/bin/Debug/netcoreapp2.0/vscode-env.dll",
"args": [],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"internalConsoleOptions": "openOnSessionStart",
"launchBrowser": {
"enabled": true,
"args": "${auto-detect-url}",
"windows": {
"command": "cmd.exe",
"args": "/C start ${auto-detect-url}"
},
"osx": {
"command": "open"
},
"linux": {
"command": "xdg-open"
}
},
"env": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
},
{
"name": ".NET Core Attach",
"type": "coreclr",
"request": "attach",
"processId": "${command:pickProcess}"
}
]
}
在VSCode launch.json中,您可以使用“ env”并在那里配置所有环境变量:
{
"version": "0.2.0",
"configurations": [
{
"env": {
"NODE_ENV": "development",
"port":"1337"
},
...
}
]
}
对于更高级的Go语言方案,您可以加载环境文件,如下所示:
{
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 2345,
"host": "127.0.0.1",
"program": "${workspaceFolder}",
"envFile": "${workspaceFolder}/.env",
"args": [],
"showLog": true
}
]
}
将.env文件放在您的文件夹中,然后添加var,如下所示:
KEY1="TEXT_VAL1"
KEY2='{"key1":val1","key2":"val2"}'
详细信息:https : //medium.com/@reuvenharrison/using-visual-studio-code-to-debug-a-go-program-with-environment-variables-523fea268271
我的回复还很晚。我遇到了同样的问题。我在Windows 10上。这是我做的:
set myvar1=myvalue1
code
,然后按ENTER
(可选)您也可以使用“控制面板”->“系统属性”窗口更永久地设置变量
希望这可以帮助。
因为它不能回答您的问题,但是搜索vm参数时,我在该页面上跌跌撞撞,似乎没有其他内容。因此,如果您想传递vm参数,就像这样
{
"version": "0.2.0",
"configurations": [
{
"type": "java",
"name": "ddtBatch",
"request": "launch",
"mainClass": "com.something.MyApplication",
"projectName": "MyProject",
"args": "Hello",
"vmArgs": "-Dspring.config.location=./application.properties"
}
]
}