Search code examples
c#.net-core.net-core-2.0

Configuration for console apps .net Core 2.0


In .net Core 1 we could do this:

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

And that gave use the Configuration object that we could then use in our console app.

All examples for .net core 2.0 seem to be tailored to the new way Asp.Net core config is created.

What is the way to create configurations for console apps?

Update: this question is not related to Asp.net core. Please do not add asp.net core tags when editing.


Solution

  • It seems there is no change, as Jehof says.

    ConfigurationBuilder is in its own package, as Jeroen Mostert says.

    But make sure you also have the Microsoft.Extensions.Configuration.Json package, where the .AddJsonFile() extension lives.

    In summary, you need the following two NuGet packages:

    • Microsoft.Extensions.Configuration (2.0.0)
    • Microsoft.Extensions.Configuration.Json (2.0.0)