0

I have a Class Library project based on .NET 6.

I'm trying to load a custom JSON configuration file, and either create/instance an IConfiguration instance based on that.

I installed Microsoft.Extensions.Configuration version 5.0.0

The below code is working for Microsoft.Extensions.Configuration version 3.0

But SetBasePath is not working anymore and I couldn't find the what is the new way?

How can I fix that?

public static IConfigurationRoot GetAppSettings()
{
    var applicationExeDirectory = ApplicationExeDirectory();

    var builder = new ConfigurationBuilder()
    .SetBasePath(applicationExeDirectory)
    .AddJsonFile($"appsettings.json", optional: false, reloadOnChange: true);
    return builder.Build();
}
OguzKaanAkyalcin
  • 621
  • 2
  • 8
  • 25

1 Answers1

1

I found the solution.

I installed Microsoft.Extensions.Configuration.Json (v5) package and then SetBasePath and AddJsonFile methods worked!

OguzKaanAkyalcin
  • 621
  • 2
  • 8
  • 25