launchSettings.json & Debug Profile in ASP.NET Core

The launchSettings.json file is used to store the configuration information, which describes how to start the ASP.NET Core application, using Visual Studio. The file is used only during the development of the application using Visual Studio. It contains only those settings that required to run the application. This file is ignored when we publish the app.

launchSettings

You will find the launchSettings.json file under the folder properties.

Create a new ASP.NET core web application with the name LaunchSettingsExample. Choose .NET Core & ASP.NET Core 3.1. You will see the following contents in the launchSettings.json file

The file has two sections. One is iisSettings and the other one is profiles section

iisSettings: contains the settings required to debug the application under the IIS or IIS Express.

profiles section contains the debug profiles. Our example file contains two profiles IIS Express & LaunchSettingsExample (same as the name of the project). Visual Studio creates these profiles when it creates the project.

Debug Profiles / Launch Profiles

The IIS Express & LaunchSettingsExample are also goes by the name Debug Profiles or Launch Profiles.

While debugging the App via Visual Studio, We need to select Profile. We do that by selecting the dropdown next to the debug icon as shown below.

The debug profile determines how to application starts. If you look at the commandName option under the IIS Express, it mentions IISExpress. This is how Visual Studio knows to invoke the IIS Express, when we start the app. Similarly commandName project starts the app under the Kestrel web server.

Creating the new debug profile

To Create a new debug profie

  1. Select Project
  2. Right Click and click on Property option
  3. Select Debug Tab
  4. Click on the New button
  5. Enter the name of the profile and click ok.
  6. Under the Environment Variables tab create ASPNETCORE_ENVIRONMENT and give it a value
  7. Under Launch select the appropriate Launch command. Available options are IIS, IISExpress, Project & Executables
  8. Save
  9. Choose the Dropdown under the debug Icon
  10. Select the newly created Profile
  11. Click debug to start the application using the new profile
Create new debug profile in Visual Studio

Now, if you open the launchSettings.json file, you will see the newly created profile Custom

Modifying the launchSettings.json

The better way to modify the launchSettings

  1. Select Project
  2. Right Click and click on Property option
  3. Select Debug Tab

Visual Studio automatically saves all the settings in the launchSettings.json. You can also directly modify the launchSettings.json

Launch Configuration

The debug tab under project -> Properties has few important options.

Launch/commandName:

This option determines how the application starts. The available options are

  1. IIS: Launches the Application IIS Webserver
  2. IISExpress: Uses IIS Express, which is a lightweight version of IIS to launch the application.
  3. Project: Launches the application using the Kestrel Web server
  4. Executables: Creates a self-contained executable file.

Environment Variables:

This option allows us to add/remove Environment Variables. The most important one is ASPNETCORE_ENVIRONMENT, which allows us to choose the application stage. The Application stage can be Development, Staging & Production, or anything we choose. The ASP.NET Configuration system reads this value to configure the Application.

Hosting Model:

Another important feature is choosing the Hosting Model. This option comes into the picture if we choose the IIS or IISExpress as launch options.

launchBrowser: A value of true here, will loads the application in the browser automatically.

Reference

LaunchSettings Support for MAC

Leave a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top