Is there any way to set environment variables in Visual Studio Code?

前端 未结 8 1182
眼角桃花
眼角桃花 2020-12-04 17:26

Could you please help me, how to setup environment variables in visual studio code?

8条回答
  •  感动是毒
    2020-12-04 18:07

    Assuming you mean for a debugging session(?) then you can include a env property in your launch configuration.

    If you open the .vscode/launch.json file in your workspace or select Debug > Open Configurations then you should see a set of launch configurations for debugging your code. You can then add to it an env property with a dictionary of string:string.

    Here is an example for an ASP.NET Core app from their standard web template setting the ASPNETCORE_ENVIRONMENT to 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}"
        }
      ]
    }
    
    

提交回复
热议问题