I have ASP.Net web form application created using Visual Studio IDE. The app has code that uses environment variable like this:
Environment.GetEnvironmentVariable("key")
The reason to use environment variable is for deploying in staging and production environment as a containerised app. But how do I run Visual Studio debug mode locally to use line break? Or how do I add environment variable in debug mode?
Preferably the environment variable is specific to the application locally.
There is no environment variable being set, so the code failed
‘Environment.GetEnvironmentVariable("key")"
2
Answers
You can use the launchSettings.json feature to setup local environment variables for debug purposes. Here is the link to the documentation. Hope this helps.
Web.Config Transformation can generate different web.config files under different publishing environments, which is very convenient and practical.
There is a default web.config in the newly created web project, and the format can also be defined as web.[name].config file. The rules defined in this configuration file will modify the web.config file when publishing.
In the default project, Web.Debug.config and Web.Release.config files will be created, corresponding to the Debug and Release environments respectively.
2. Add Test config Transformation file
On web.confg, right click, Add Config Transform, VS will add Transformation file Web.Test.config for the newly created Test configuration
3. Modify the Web.Test.config file.
This code needs to be uncommented.
5. Open it with Notepad and scroll to the bottom:
Just add this paragraph.