You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Run that launch configuration from the VSCode Debugger extension. Step through the following C# statement Environment.GetEnvironmentVariable("SOME_KEY").
Also notice the launch.json opened in VSCode warns you that the env and environment properties in your configuration are not supported, it underlines them with yellow squigglies, hovering the mouse over them displays a bubble that says "Property env is not allowed". The environment property is not documented so that makes sense, but the env is documented so one would expect it to work. Those warnings are also reported in VSCode's "problems" tab.
Logs
C# log
Post the output from Output-->C# here
C# LSP Trace Logs
Post the output from Output-->C# LSP Trace Logs here. Requires the `C#` output window log level to be set to `Trace`
Environment information
VSCode version: 1.98.2 C# Extension: 2.69.25 Using OmniSharp: false
TLDR: You want to add your environment variables to a <project-directory>/Properties/launchSettings.json file.
Full Explanation: There are two different type values you can use to debug a C# program -- you can use dotnet, which call into the project system to determine how the specified project should be debugged, or you can use coreclr (or one of the other lower-level debug adapter types depending on what the type of project you have is) where you can fully specify how you want to debug, but you need to keep that in sync with any project changes (example: the target framework). dotnet doesn't support env (hopefully IntelliSense was giving you squiggles about this?). Instead, it pulls environment variables from the 'Properties/launchSettings.json' file, which is not just VS Code-specific, but also used by full VS, and the .NET CLI. If you need to have this specified in launch.json, you can switch to the coreclr type. In this case I would suggest using the '.NET: Generate Assets for Build and Debug' command from the command well, as that will give you a good launch.json template to start from.
Type: Bug
Issue Description
According to the documentation at https://code.visualstudio.com/docs/csharp/debugger-settings#_environment-variables a user may set the
env
launch property to define environment variables but that doesn't work.Steps to Reproduce
Define a launch configuration in your launch.json, and set some environment variables using either
env
orenvironment
Run that launch configuration from the VSCode Debugger extension. Step through the following C# statement
Environment.GetEnvironmentVariable("SOME_KEY")
.Expected Behavior
Environment.GetEnvironmentVariable("SOME_KEY")
returns"some_value"
Actual Behavior
Environment.GetEnvironmentVariable("SOME_KEY")
returnsnull
Also notice the launch.json opened in VSCode warns you that the
env
andenvironment
properties in your configuration are not supported, it underlines them with yellow squigglies, hovering the mouse over them displays a bubble that says "Property env is not allowed". Theenvironment
property is not documented so that makes sense, but theenv
is documented so one would expect it to work. Those warnings are also reported in VSCode's "problems" tab.Logs
C# log
C# LSP Trace Logs
Environment information
VSCode version: 1.98.2
C# Extension: 2.69.25
Using OmniSharp: false
Dotnet Information
.NET SDK: Version: 9.0.104 Commit: 7931ad4860 Workload version: 9.0.100-manifests.dc2cb94f MSBuild version: 17.12.27+7931ad486Runtime Environment:
OS Name: ubuntu
OS Version: 24.04
OS Platform: Linux
RID: ubuntu.24.04-arm64
Base Path: /usr/lib/dotnet/sdk/9.0.104/
.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.
Host:
Version: 9.0.3
Architecture: arm64
Commit: 7931ad4860
.NET SDKs installed:
8.0.114 [/usr/lib/dotnet/sdk]
9.0.104 [/usr/lib/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.14 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.3 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.14 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.3 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
None
Environment variables:
Not set
global.json file:
Not found
Learn more:
https://aka.ms/dotnet/info
Download .NET:
https://aka.ms/dotnet/download
Visual Studio Code Extensions
Extension version: 1.17.64
VS Code version: Code 1.98.2 (ddc367ed5c8936efe395cffeec279b04ffd7db78, 2025-03-12T13:32:45.399Z)
OS version: Windows_NT arm64 10.0.26100
Modes:
Remote OS version: Linux arm64 5.15.167.4-microsoft-standard-WSL2
System Info
canvas_oop_rasterization: enabled_on
direct_rendering_display_compositor: disabled_off_ok
gpu_compositing: enabled
multiple_raster_threads: enabled_on
opengl: enabled_on
rasterization: enabled
raw_draw: disabled_off_ok
skia_graphite: disabled_off
video_decode: enabled
video_encode: enabled
vulkan: disabled_off
webgl: enabled
webgl2: enabled
webgpu: enabled
webnn: unavailable_software
The text was updated successfully, but these errors were encountered: