.NET Core 2.1.0
var builder = new ConfigurationBuilder() .SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
var config = builder.Build();
3. Install the following dependencies:
Microsoft.Extensions.Configuration
Microsoft.Extensions.Configuration.json
4. Then, IMPORTANT: Right-click on the appsettings.json file -> click on Properties -> select Copy if newer:
Finally, you can do:
config["key1"]
Considering that my config file will look like this:
{ "ConnectionStrings": "myconnection string here", "key1": "value here" }