DEV Community

loading...

Envrionment in .NET Core

Aman Singh Parihar
I work as a software engineer and having experience in web technologies. I like to share my knowledge with the community and aspire to learn cool things.
・2 min read

We can setup different environments while developing an application in .net core.

When we first create an application in .net core using the web api template, we have two different profiles available in the launchSettings.json.

  1. IIS Express
  2. {Name of the project}

Note: launchSettings.json file is only available at the time of development.

Lets try to understand this file.

In the profile section we have two profiles available.

  1. IIS Express
    As we can see commandName is set to IISExpress, and in the environment varialble section we have ASPNETCORE_ENVIRONMENT variable set to Development.

  2. {Name of the Project}
    Here we can see commandName is set to Project, and in the environment varialble section we have ASPNETCORE_ENVIRONMENT variable set to Development.

We can select any of these profile to run our application.

If commandName is set to IISExpress, then the application will be launched using IISExpress and if the commandName will be set to Project, then the application will be launched using kestrel server along with a reverse proxy server.

image

image

And as in both the cases ASPNETCORE_ENVIRONMENT set to development, so the environment will be development. We can check for different environment in the startup.cs file using various extension methods.

And if no value is set for ASPNETCORE_ENVIRONMENT variable in launchSettings.json, then it will look in the System Environment Variable and if it is also not set there, then the value will be production by default.

Discussion (0)