skip to Main Content

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


  1. 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.

    Login or Signup to reply.
  2. 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.

    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.
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search