Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 538
zaitsman Avatar asked Aug 24 '17 01:08

zaitsman


People also ask

How do I run a .NET Core console app?

In . NET Core, it runs from the dll, so you have to just run the application by running the command prompt and using the command - dotnet run. Open your command prompt and go to that folder where your application persists.

Can I use app config in .NET Core?

Application configuration in ASP.NET Core is performed using one or more configuration providers. Configuration providers read configuration data from key-value pairs using a variety of configuration sources: Settings files, such as appsettings. json.


1 Answers

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)
like image 90
Henning Klokkeråsen Avatar answered Oct 04 '22 16:10

Henning Klokkeråsen