Configuration for console apps .net Core 2.0

zaitsman picture zaitsman · Aug 24, 2017 · Viewed 19.9k times · Source

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.

Answer

Henning Klokkeråsen picture Henning Klokkeråsen · Sep 6, 2017

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)