I am building a .NET Framework WPF application, however, I want to use IConfigurationBuilder, which is a part of the newer (.NET Core and up) Microsoft.Extensions.Configuration namespace. My understanding is that .NET Framework apps traditionally use the app.config file in conjunction with ConfigurationManager class.

Unfortunately, I have to use .NET Framework. Despite this, I would strongly prefer IConfigurationBuilder as a) this is the more modern approach, b) it meshes well with adding services/DI (through Microsoft.Extensions.Hosting and the Host class), and c) it appears easier in numerous aspects than working with the older app.config setup, particularly when it comes to managing configurations for different environments.

I think I could keep app.config and still integrate with my Host setup by using the Microsoft.Extensions.Configuration.Xml NuGet (which has several AddXmlFile methods). I believe I could also just delete the app.config (and Settings.settings) and add an appsettings.json.

My question is: can I expect any issues with choosing appsettings.json over app.config in a .NET Framework application? I am curious if others have done this, and if so, why they did this. I welcome any advice or insight related to this.

  • How exactly do you intend to use ConfigurationBuilderor IConfigurationBuilder in your .Net Fw application? As you said, those classes are not part of the classic .NET framework - are you thinking of to backporting them?
    – Doc Brown
    Commented May 23, 2023 at 8:19
  • The NuGet package for those is supported in .NET Framework since 4.6.2 (and .NET Standard 2.0); so as long as you are targeting a newer version of Framework 4.x, preferably 4.8 which is still in support (4.6.2 is obsolete and out-of-support), then you should be fine: nuget.org/packages/Microsoft.Extensions.Configuration.Json/… Commented May 24, 2023 at 7:36
  • .exe.config is still used for purposes unrelated to your application's custom settings/config. The CLR will automatically try to locate MyProgram.exe.config for these, and will expect the file to match the XML configuration schema. On the other hand, appSettings.json is far more loosely defined, and more importantly is unrelated to any .NET CLR feature, so it cannot replace exe.config for anything but your own custom config). Commented May 24, 2023 at 7:46
  • @BenCottrell Thank you for confirming about compatibility of the NuGet packages (relatively new developer here, so still figuring out where I can find out the answers to all my questions!). Regarding the .exe.config it's good to know about it. I see that when I do not have an app.config, but rather an appsettings.json, building the project results in the .exe.config but app.config is not re-generated. Which is what I think you are saying and is ideal for my purposes - I ultimately would like to use appsettings.json and the associated, newer, libraries.
    – JD136
    Commented May 26, 2023 at 21:45
  • At some point, I am expecting to update the project itself to be .NET 6, but confirming that the NuGet (and the Framework overall) is compatible with appsettings.json and associated, newer, libraries, gives me more confidence about the application. Thank you @BenCottrell!
    – JD136
    Commented May 26, 2023 at 21:46


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.