How to set environment variables for C# in VS2019

Viewed 1684

I need to set up something like this but option from VS19 is not there, does anyone know how can I set this up from a file or some other way?
enter image description here

3 Answers

Right-click on your startup project and go to Properties. Open the Debug tab and you will see an option to set environment variables for your project. If you want to set it from code at runtime, try calling this method: Environment.SetEnvironmentVariable("variableName", "value");

You can add the following lines in your .csproj/.vcxproj file under the desired configuration's <PropertyGroup> node:

<LocalDebuggerEnvironment>RP_STOPPING_COMMAND_DISABLE=1</LocalDebuggerEnvironment>
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>

Before starting Visual Studio:

  1. Start a command prompt window (cmd.exe).
  2. Set the desired environment variable(s): (C:> SET VAR=value)
  3. Run Visual Studio from the command window (C:> "C:\Program Files...\Common7\IDE\devenv.exe")

The VS process and any processes it starts (i.e. debug processes) will inherit the environment changes, and it won't affect the system.

Related