What is launchsetting.json in ASP.NET Core

This json file holds project specific settings associated with each debug profile, Visual Studio is configured to use to launch the application, including any environment variables that should be used. You can define framework for your project for compilation and debugging for specific profiles. This file is placed in Properties folder.

In above paragraph, I mentioned about visual studio project debug profiles and environment variables. Before we move ahead, it’s important to understand about these 2.

Environment Variables

As mentioned on Wikipedia “Environment variables are a set of dynamic named values that can affect the way running processes will behave on a computer. They are part of the environment in which a process runs.” So similarly, there are various environment variables present in ASP.NET 5 which can be set that will affect various parts of the runtime. You can find the complete list here. But for this post, we are interested in ASPNET_ENV variable. This variable actually defines the environment the application is currently running in. There are 3 values are used by convention: Development, Staging, and Production. We are also allowed to set any value which we want.

And if you see Startup.cs class code, you will see these values are used.

And the default web host for ASP.NET application created using Visual Studio 2015 is IIS/IIS express. Therefore, even for empty website, “Microsoft.AspNet.Server.IIS” dependency is defined in project.json. And in case of web site, there can be 3 different profiles. You can manage settings for each profile in debug tab of project property menu.

As per the screenshot, you can also define environment variables, launch URL, specific runtime to use for each profile. Please remember the value for ASPNET_ENV (or Hosting:Environment) is case insensitive. But when you try to define the same key again for a different value, you will get duplicate key error.

So when you modify the default settings for your project, changes are persisted in launchSettings.json. Now let’s take a look at launchsetting.json code.

The first part defines the IIS settings as IIS is the default web host choice. And there are 3 profiles “IIS Express”, “web” and “kestrel” in profile section. And for each profile, environment variable, runtime version to use and it’s command name is also defined. As mentioned earlier, command names are defined in project.json file. So when you launch your application using any of the option, setting defined in launchsetting will be used for your web application.

We can run the web command from a command prompt using dnx like dnx web. This will host your application and the settings will be picked up from commands.

Startup Conventions

As mentioned earlier that ASPNET_ENV can have 3 values convention: Development, Staging, and Production. And with ASP.NET 5, the Startup class is used for bootstraping the application and loading all your configuration. And there is also a convention exists for Startup.cs and ASPNET_ENV values. You are allowed to create Startup class with environment variable name Startup{EnvironmentName} (for example StartupDevelopment). So you can have StartupDevelopment, StartupStaging and StartupProduction. and based on the ASPNET_ENV environment variable value, that Startup class is used. Thus, it gives you the flexibility to configure Startup settings for different environment.

That’s all folks. Keep visiting this blog and share this in your network. Please put your thoughts and feedback in comments section.

PS: If you found this content valuable and want to return the favour, then