1
votes

Is there a configuration provider already pre-configured in .net core that I can just use without having to add in boilerplate code? In the same way that app.config files just work in full .net.

I'm writing a console app in .net core 2 and it needs some settings, a connection string and a few app settings that I would have previously just tossed into the app.config file.

I've started googling about configuration in .net core and found a whole heap of documentation about how flexible it is - you just add a file, make sure it gets copied to the correct location and then spin up a configuration builder add it the correct provider build it etc. etc.

As nice and flexible as it is I don't want to clutter up my tiny console apps with this config boilerplate - it feels like we have to roll our own config for each app.

1
package up the boilerplate code into a reusable extension method and use that - Nkosi
I've found that you can add the System.Configuration.ConfigurationManager nuget package and app.config files are then magically supported without any boilerplate code. You can read settings using old-school ConfigurationManager class - Twisted

1 Answers

0
votes

Ideally, in a .NET Core application, one would choose JSON setting files over XML configuration files, but it is still possible to use legacy XML configuration files if needed.

There is an API to access application setting files; just check out the following NuGet packages: Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Xml, and this article might be a good reading: http://benfoster.io/blog/net-core-configuration-legacy-projects since it also covers the integration of app.config or web.config files, as well as how to create a custom configuration provider.