Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use System.Configuration.ConfigurationManager in .netstanard library for .net core and .netframework

I am migrating the .netframework 4.7.2 class library to .netstandard 2.0 library.

ConfigurationManager is used in the .netframework class library to read the app settings.

Any alternative option available for the System.Configuration.ConfigurationManager in .netstanard.

The migrated class library needs to be used in a .net core web API and old .netframework web application.

like image 461
Manu Avatar asked Apr 30 '20 17:04

Manu


People also ask

Does ConfigurationManager work in .NET Core?

ConfigurationManager was added to support ASP.NET Core's new WebApplication model, used for simplifying the ASP.NET Core startup code.

How do I add a reference to System configuration ConfigurationManager?

Right click the project and choose add reference, browse "Assemblies" and tick the System. Configuration assembly.

What is ConfigurationManager configuration?

The ConfigurationManager class enables you to access machine, application, and user configuration information. This class replaces the ConfigurationSettings class, which is deprecated. For web applications, use the WebConfigurationManager class.

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.

What is system configurationmanager in netstanard?

ConfigurationManager is used in the .netframework class library to read the app settings. Any alternative option available for the System.Configuration.ConfigurationManager in .netstanard. The migrated class library needs to be used in a .net core web API and old .netframework web application.

Is it possible to create a standard library using configurationmanager class?

It is not possible to create .NET Standard library which references System.Configuration.ConfigurationManager package and uses ConfigurationManager class. Once library adds reference to .NET Core specific package it ceases to be portable .NET Standard library since it is bound to framework specific package.

How do I use configurationmanager in a project?

Namespace: System.Configuration. To use the ConfigurationManager class, your project must reference the System.Configuration assembly. By default, some project templates, like Console Application, do not reference this assembly so you must manually reference it. using System.Configuration; This class provides two properties:

How to install configurationmanager in ASP NET Core?

You could install ConfigurationManager via nuget package, which targets .Net Standard 2.0. As for ASP.Net Core, have a look at Microsoft.Extensions.Configuration. As I said, you should not depend directly on how the configuration is obtained in a class library. Keep your class library flexible.


Video Answer


1 Answers

You could install ConfigurationManager via nuget package, which targets .Net Standard 2.0.

As for ASP.Net Core, have a look at Microsoft.Extensions.Configuration.

like image 74
weichch Avatar answered Sep 19 '22 05:09

weichch