Skip to content

launch.json "env" attribute ignored from VSCode when debugging #8320

Open
@xas

Description

@xas

Issue Description

On a remote WSL configuration, I try to run from VSCode a profile defined in /.vscode/launch.json
The parameter "env" seems ignored

{
  "name": "C#: My Project Debug",
  "type": "dotnet",
  "request": "launch",
  "projectPath": "${workspaceFolder}/path.to.my.csproj",
  "env": {
      "ASPNETCORE_ENVIRONMENT": "Staging"
  }
},

Steps to Reproduce

Create a simple aspnet project

in /.vscode/launch.json have a profile

{
  "name": "C#: My Project Debug",
  "type": "dotnet",
  "request": "launch",
  "projectPath": "${workspaceFolder}/path.to.my.csproj",
  "env": {
      "ASPNETCORE_ENVIRONMENT": "Staging"
  }
},

In Program.cs:

var builder = WebApplication.CreateBuilder(args);
string Env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
Console.WriteLine($"- {Env}");
Console.WriteLine(builder.Environment.EnvironmentName);

F5 from VSCode

Expected Behavior

Output should display two lines :

- Staging
Staging

Actual Behavior

Output display show no environment variable set

- 
Production

Remarks

I tried also with a classic configuration on windows (no remote WSL), same behavior

I got no issue if I add to my project the file Properties/launchSettings.json and define environmentVariables values

But I assumed that you can use launch.json without launchSettings.json

Environment information

VSCode version: 1.100.2
C# Extension: 2.76.27
Using OmniSharp: false

Dotnet Information .NET SDK: Version: 9.0.105 Commit: b7deac6d42 Workload version: 9.0.100-manifests.3b27a542 MSBuild version: 17.12.32+b7deac6d4

Runtime Environment:
OS Name: ubuntu
OS Version: 24.04
OS Platform: Linux
RID: ubuntu.24.04-x64
Base Path: /usr/lib/dotnet/sdk/9.0.105/

.NET workloads installed:
There are no installed workloads to display.
Configured to use loose manifests when installing new manifests.

Host:
Version: 9.0.4
Architecture: x64
Commit: b7deac6d42

.NET SDKs installed:
8.0.116 [/usr/lib/dotnet/sdk]
9.0.105 [/usr/lib/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.16 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 9.0.4 [/usr/lib/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.16 [/usr/lib/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 9.0.4 [/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 Author Version Folder Name
csdevkit ms-dotnettools 1.19.63 ms-dotnettools.csdevkit-1.19.63-linux-x64
csharp ms-dotnettools 2.76.27 ms-dotnettools.csharp-2.76.27-linux-x64
csharp-organize-usings jeremycaron 1.0.6 jeremycaron.csharp-organize-usings-1.0.6
csharp-to-plantuml pierre3 1.4.0 pierre3.csharp-to-plantuml-1.4.0
docker docker 0.6.0 docker.docker-0.6.0-linux-x64
git-graph mhutchie 1.30.0 mhutchie.git-graph-1.30.0
nugetpackagemanagergui aliasadidev 2.1.1 aliasadidev.nugetpackagemanagergui-2.1.1
plantuml jebbs 2.18.1 jebbs.plantuml-2.18.1
prettyxml PrateekMahendrakar 6.0.0 prateekmahendrakar.prettyxml-6.0.0
resx-editor timheuer 0.2.34 timheuer.resx-editor-0.2.34
vscode-containers ms-azuretools 2.0.1 ms-azuretools.vscode-containers-2.0.1
vscode-dotnet-runtime ms-dotnettools 2.3.3 ms-dotnettools.vscode-dotnet-runtime-2.3.3
vscode-httpyac anweber 6.16.7 anweber.vscode-httpyac-6.16.7
vscode-nupkg eridem 1.0.1 eridem.vscode-nupkg-1.0.1
vscodeintellicode-csharp ms-dotnettools 2.2.3 ms-dotnettools.vscodeintellicode-csharp-2.2.3-linux-x64

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions