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")"
CodePudding user response:
You can use the launchSettings.json feature to setup local environment variables for debug purposes. Here is the
- First add the Test configuration
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.
- Find the current project.
5. Open it with Notepad and scroll to the bottom: Just add this paragraph.
- If Visual Studio pops up a prompt box, click Overwrite, and then save.