Why aren't my environment variables being set in Visual Studio 2026?

1 day ago 1
ARTICLE AD BOX

I'm working on a Windows machine which has been locked down fairly heavily, so I'm unable to set environment variables on my machine. Since I'm using Visual Studio 2026, I tried setting the environment variables via the projects properties, as you can see below.

launchSettings.json:

{ "profiles": { "MyProject": { "commandName": "Project", "environmentVariables": { "MY_VARIABLE": "my_value" } } } }

Properties -> Debug -> General:

environment variables in vs 2026

I'm then trying to retrieve the value of the environment variables value with Environment.GetEnvironmentVariable() like so:

TestVariable = Environment.GetEnvironmentVariable("MY_VARIABLE") ?? string.Empty;

However, when running this locally, this code always returns an empty string, suggesting it couldn't find the environment variable.

I'm doing all of this inside of an NUnit project, and I've tried running it in debug mode. Also, this code works just fine when plugged into our GitLab CI/CD pipeline with the environment variable set via our .gitlab-ci.yml file.

Why aren't the values of my environment variables set via Visual Studio 2026 being respected?

Read Entire Article