Home > Software engineering >  How to use line break to debug Web App in Visual Studio that uses environment variable
How to use line break to debug Web App in Visual Studio that uses environment variable

Time:12-16

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 enter image description here

  1. First add the Test configuration

enter image description here

enter image description here

enter image description here 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

enter image description here 3. Modify the Web.Test.config file. This code needs to be uncommented.

enter image description here

  1. Find the current project.

enter image description here 5. Open it with Notepad and scroll to the bottom: Just add this paragraph.

enter image description here

  1. If Visual Studio pops up a prompt box, click Overwrite, and then save.
  • Related