Need to set Debug-specific Environment Variable in VS.NET 2017

visual studio 2019 set environment variables for debugging
launch.vs.json environment variables
visual studio debugger view environment variables
visual studio debugging environment path
visual studio debug command line arguments environment variables
vscode debug set env variables
set environment variable tracedesigntime = true and restart visual studio to investigate
visual studio project variables

All,

I apologize if this is the world's dumbest question.

I found this: https://stackoverflow.com/a/155363/463196

I can't find the menu item when following the answer:

I guess I need a visual walkthrough for dummies, unless this has changed from VS.NET 2008 and VS.NET 2017.

Edit:

The reason I need this ... I am doing C#, Azure. There is an environment variable that if set for Debug, will make it so the Storage goes to a mock instead of a live Azure Storage. I need this so that I can happily go from test to Prod w/out having touches on my App.Config file.

To answer the actual question that you asked, modify your project file to use the MSBuild AfterBuild target with the Exec task. For example:

<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Debug' ">
    <Exec Command="set MY_ENVIRONMENT_VARIABLE_NAME=\"DEBUG\"" />
</Target>
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release' ">
    <Exec Command="set MY_ENVIRONMENT_VARIABLE_NAME=\"RELEASE\"" />
</Target>

Since you mentioned app.config, a more elegant solution might be to look into automatically transforming that file on build (which entails substituting appropriate values for the specific release configuration), again via MSBuild. [An example of this, using the TransformXml MSBuild task, can be found on this very site.]

For a less manual process, you can install Microsoft's own SlowCheetah extension which will give you an option to add and configure these transforms directly within Visual Studio. This extension is basically just a UI wrapper around TransformXml, and as such does not need to be present on any CI/build machines.

ASP.NET Core - Environment Variable, How do I debug in release mode in Visual Studio 2017? Visual Studio 2017 - setting environment variables for debugged process fixed in: visual studio 2019 version 16.1 debugger Fixed In: Visual Studio 2019 version 16.1 Preview 2 windows 10.0 Fixed in: Visual Studio 2017 version 15.9 visual studio 2017 version 15.5 Fixed In: Visual Studio 2019 version 16.1 Preview 1

You are mixing something up here! There are Debug specific variables for the compiler and these are set within the Visual Studio IDE. But this is not what you need! You'll want to access real environment variables from the Windows operating system. See How do I get and set Environment variables in C#? for details. And, in case you don't know, these can be set from a CMD prompt by using the 'SET' command or from the 'Advanced system settings' of the Windows Control Panel. If your application is running within IIS, you may need to restart the machine to get the latest environment variables within your program. Every program always inherits the environment variables from its parent process.

What is the difference between Release and Debug modes in Visual , solution configurations. You can add others if you want. There are multiple environment variables, VS->Project Property->Debug->Environment Variables and System Properties->Environment Variables. It seems you want to secure the information from anyone who could access the code. If so, the Environment variables in VS will not be fufill. Its value could be checked by launchSettings.json file.

This might be an old post, but the answers so far given doesn't do what I think the OP is asking for. I am working with Azure right now and what you are asking for is what I've done in my project.

So basically I have my environment variables set in Azure and when debugging, I can't access them, but there is a solution for that.

Just go to Project Properties => Debug and from there add the specific environment variables.

This way, when testing locally, you will get the same output in regards to environment variables as when actually connecting to Azure.

Visual Studio 2017, click OK on both dialogs and start your debugging session. You are going to see that only one environment variable is set in the debugged  Specifies the name of an environment variable that will be used when the project is built or when the project is run from Visual Studio. Value. Specifies the path for an environment variable. Enter a path in the Value column, or use the Select Folder button. If you use Select Folder, the currently highlighted environment variable will be set to

Set Environment Variables for Debug, Launch, and Tools with , NET · NuGet · Xamarin Visual Studio has a mechanism to customize environment variables for Debug targets and custom tasks can have their environments Configuration-specific variables defined in CppProperties.json are December 2017 · November 2017 · October 2017 · September 2017  1 Need to set Debug-specific Environment Variable in VS.NET 2017 Jan 17 '19. 1 Same source folder in to TFS systems? Aug 17 '17. View all questions and answers →

How to: Use Environment Variables in a Build, When you build projects, it is often necessary to set build options using information that is not in the project file or the files that comprise your  Thanks for your answer. I'm working on a node application and there using some environment variable like as process.env.VAR_NAME, I want the variables when running the project. Is the configuration env variables will be available in this case? It's not working. – Shakti Kumar Das Feb 6 '18 at 11:23

Setting and using Environment Variables in Visual Studio 2017, Hi tripleagentj,. There are multiple environment variables, VS->Project Property->​Debug->Environment Variables and System Properties->  The Machine option value indicates to set the environment variable at the system level. If the option value is changed to User, the environment variable is set for the user account. When the ASPNETCORE_ENVIRONMENT environment variable is set globally, it takes effect for dotnet run in any command window opened after the value is set. web.config

Comments
  • Strange how that answer got so many votes. He actually described a setting that is only available for C++ projects, as noted in a comment. You'll of course have to tell us what you want to accomplish to get an answer that is actually useful.
  • @HansPassant I am doing C#, Azure. There is an environment variable that if set for Debug, will make it so the Storage goes to a mock instead of a live Azure Storage. I need this so that I can happily go from test to Prod w/out having touches on my App.Config file.
  • Don't tell me, put it in your question. Also explain why you can't simply use Environment.SetEnvironmentVariable() or a config setting or Debugger.IsAttached to accomplish this.
  • @HansPassant Which one of those approaches entails not modifying my source code everytime I want to switch between Dev and Production? I want to be able to build/run Debug and have it configured for Debug, and then build Release and have it configured for Production. Also, please keep in mind I'm coming from a Java background, so I am not completely familiar with these different approaches.
  • This looks like the answer for me. Not sure why you got downvoted