What is launchsetting.json in ASP.NET CORE?
This json record holds extend particular settings related with each troubleshoot profile, Visual Studio is arranged to use to dispatch the application, including any condition factors that ought to be utilized. You can characterize structure for your venture for accumulation and troubleshooting for particular profiles. This document is set in Properties envelope.
In above passage, I specified about visual studio extend troubleshoot profiles and condition factors. Before we advance, it's essential to comprehend 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.
if you see Startup.cs class code, you will see these values are used.
The above code is checking if running environment is development or not env.IsDevelopment()
Visual Studio Project Debug Profiles
Visual studio underpins the numerous troubleshoot profiles, related with IIS express and summons characterized in project.json.
ASP.NET 5 ships with support for 3 unique servers:
- Microsoft.AspNet.Server.IIS
- Microsoft.AspNet.Server.WebListener (WebListener)
- Microsoft.AspNet.Server.Kestrel (Kestrel)
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. What's more, in the event of site, there can be 3 distinct profiles. You can oversee settings for each profile in troubleshoot tab of venture 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 ASP_ENV (Hosting:Enviroment) 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 initial segment characterizes the IIS settings as IIS is the default web have decision. Also, there are 3 profiles "IIS Express", "web" and "kestrel" in profile segment. What's more, for each profile, condition variable, runtime rendition to utilize and its order name is likewise characterized. As said before, charge names are characterized in project.json document. So when you dispatch your application utilizing any of the choice, setting characterized in launchsetting will be utilized 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 said before that ASPNET_ENV can have 3 esteems tradition: Development, Staging, and Production. Furthermore, with ASP.NET 5, the Startup class is utilized for bootstraping the application and stacking your whole setup. What's more, there is additionally a tradition exists for Startup's and ASPNET_ENV esteems. You are permitted to make Startup class with condition variable name Startup {EnvironmentName} (for instance StartupDevelopment). So you can have StartupDevelopment, StartupStaging and StartupProduction. Also, in view of the ASPNET_ENV condition variable esteem, that Startup class is utilized. Along these lines, it gives you the adaptability to design Startup settings for various conditions.