Adding appsettings.json to a .Net Core console application

Firstly add the appsettings.json file to the solution

   "AppSettings": {
   "Key1": "This is the value for Key1"

Set the .json file to copy to the output directory (this is the bin folder)

Add Microsoft.Extensions.Configuration.Json from Nuget

The read the file

IConfiguration config = new ConfigurationBuilder()
 .AddJsonFile("appsettings.json", true, true)

var key1 = config["AppSettings:Key1"];

Run the code

Leave a Reply