I have two projects, a 1.1.0 ASP.NET Core project and a reference to a 4.5.2 project.
I want to get values from the appsettings.json file to my 4.5.2 project. The appsettings.json file is in the core project.
Tried this from my 4.5.2 project with no luck:
var mailServer = ConfigurationManager.AppSettings["MailServer"];
How can I access the values from my 4.5.2 project?
ConfigurationManager
works with XML-based configuration files that have specific format and doesn't know how to read the custom JSON file.
Cause you use appsettings.json
for the ASP.NET Core project as well, you may add dependencies to Microsoft.Extensions.Configuration and Microsoft.Extensions.Configuration.Json packages and read settings using ".NET Core approach":
var builder = new ConfigurationBuilder()
.AddJsonFile(@"<path to appsettings.json>");
var configuration = builder.Build();
// configuration["MailServer"]
Of course, as appsettings.json
is a simple JSON file, you may always directly deserialize using any JSON provider.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With