What are the various JSON files available in C# ASP.NET Core?


ASP.net Core is re-architected from prior versions of ASP.net,where the configuration was relying on System.Configuration and xml configurations in web.config file. In ASP.net Core, a new easy way to declare and access the global settings for solution, project specific settings,client specific settings etc..The new configuration model, works with XML,INI and JSON files.

Different configuration json files in ASP.net Core There are mainly 6 configuration JSON files in ASP.net Core.

global.json
launchsettings.json
appsettings.json
bundleconfig.json
project.json
bower.json

global.json

Example

You can define the solution level settings in global.json file.{
   "projects": [ "src", "test" ],
   "sdk": {
      "version": "1.0.0-preview2-003121"
   }
}

projects − projects property defines the location of source code for your solution. It specifies two location for projects in the solution: src and test.src contains actual application and test contains any test.

launchsettings.json

In launchsettings.json file, You can define project specific settings associated with each profile Visual Studio is configured to launch the application, including any environment variables that should be used. You can define framework for your project for compliation and debugging for specific profiles.

{
   "iisSettings": {
      "windowsAuthentication": false,
      "anonymousAuthentication": true,
      "iisExpress": {
         "applicationUrl": "http://localhost:50944/",
            "sslPort": 0
      }
   },
   "profiles": {
      "IIS Express": {
         "commandName": "IISExpress",
         "launchBrowser": true,
         "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
         }
      },
      "ASPCoreMVCHelloWorld": {
         "commandName": "Project",
         "launchBrowser": true,
         "launchUrl": "http://localhost:5000",
         "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development"
         },
         "kestrel": {
            "commandName": "kestrel",
            "sdkVersion": "dnx-clr-win-x86.1.0.0-preview2-003121"
         }
      }
   }
}

You can change settings for each profile via right click on the Project and then select properties.

appsettings.json

ASP.NET stores application configuration settings in Web.config. ASP.NET Core uses AppSettings.json to store custom application setting, DB connection strings,Logging etc.. Below is a sample of Appsettings.json −

{
   "ApplicationInsights": {
      "InstrumentationKey": ""
   },
   "Logging": {
      "IncludeScopes": false,
      "LogLevel": {
         "Default": "Debug",
         "System": "Information",
         "Microsoft": "Information"
      }
   }
}

bundleconfig.json

You can define the configuration for bundling and minification for the project.

[
   {
      "outputFileName": "wwwroot/css/site.min.css",
      // An array of relative input file paths. Globbing patterns supported
      "inputFiles": [
         "wwwroot/css/site.css"
      ]
   },
   {
      "outputFileName": "wwwroot/js/site.min.js",
      "inputFiles": [
         "wwwroot/js/site.js"
      ],
      // Optionally specify minification options
      "minify": {
         "enabled": true,
         "renameLocals": true
      },
      // Optinally generate .map file
      "sourceMap": false
   }
]

project.json

Asp.net Core uses Project.JSON file for storing all project level configuration settings.The Project.json file stores configuration information in JSON format.

{
   "dependencies": {
      "Microsoft.NETCore.App": {
         "version": "1.0.0",
         "type": "platform"
      },
      "Microsoft.ApplicationInsights.AspNetCore": "1.0.0",
      "Microsoft.AspNetCore.Diagnostics": "1.0.0",
      "Microsoft.AspNetCore.Mvc": "1.0.0",
      "Microsoft.AspNetCore.Razor.Tools": {
         "version": "1.0.0-preview2-final",
         "type": "build"
      },
      "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
      "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
      "Microsoft.AspNetCore.StaticFiles": "1.0.0",
      "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
      "Microsoft.Extensions.Configuration.Json": "1.0.0",
      "Microsoft.Extensions.Logging": "1.0.0",
      "Microsoft.Extensions.Logging.Console": "1.0.0",
      "Microsoft.Extensions.Logging.Debug": "1.0.0",
      "Microsoft.Extensions.Options.ConfigurationExtensions": "1.0.0",
      "Microsoft.VisualStudio.Web.BrowserLink.Loader": "14.0.0"
   }
}

bower.json

Bower is a package manager for the web. Bower manages components that contain HTML, CSS, JavaScript, fonts or even image files. Bower installs the right versions of the packages you need and their dependencies

Updated on: 25-Sep-2020

5K+ Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements