Reputation: 9841
The Core 1.x configuration has been answered here
ASP.NET Core configuration for .NET Core console application
Unfortunately the Core 2.0.0 API and architecture has changed slightly and by the looks of this article that it uses Dependency Injection on the Startup class now (on a WebAPI based project) which is allot simpler.
But I am not sure how to do that on a Console application as there is no underlying DI. When I try to use the following code none of the methods exist on the new 2.0.0
var builder = new ConfigurationBuilder()
.AddJsonFile($"appsettings.json", true, true) -ERROR
.AddJsonFile($"appsettings.{environmentName}.json", true, true) -ERROR
.AddEnvironmentVariables(); -ERROR
Does any body know how to add appsettings.json
into the ConfigurationBuilder?
Upvotes: 2
Views: 2508
Reputation: 9841
Turns out I have to manually add this package which contains the AddJsonFile extension - For some reason Intellisense did not suggest installing this package as it does with other things.
dependencies {
"Microsoft.Extensions.Configuration.Json": "2.0.0"
}
Upvotes: 2