Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Core 1.0 ConfigurationBuilder().AddJsonFile("appsettings.json"); not finding file

So I've finally got round to looking at Core and I've fallen at the first hurdle. I'm following the Pluralsight ASP.NET Core Fundamentals course and I'm getting an exception when trying too add the appsettings.json file to the configuration builder.

public Startup() {     var builder = new ConfigurationBuilder()         .AddJsonFile("appsettings.json");      Configuration = builder.Build(); } 

The error I'm getting is The configuration file 'appsettings.json' was not found and is not optional. But I have created the directly under my solution just like in the course video.

like image 240
Zhorian Avatar asked Jul 09 '16 14:07

Zhorian


1 Answers

public Startup(IHostingEnvironment env) {     var builder = new ConfigurationBuilder()         .SetBasePath(env.ContentRootPath)         .AddJsonFile("appsettings.json");      Configuration = builder.Build(); } 

This seems to do the trick. However unsure this is the proper way to do it. Kinda feels like a hack.

like image 150
Zhorian Avatar answered Sep 29 '22 10:09

Zhorian