I'm working on migrating an existing ASP.NET MVC app to ASP.NET Core. The solution has several class libraries (providing data access, services, etc). Many of those class libraries make use of the static ConfigurationManager.AppSettings["..."]
way of getting the config from the web.config file.
With the ASP.NET Core app, though, there is no web.config file and it appears ConfigurationManager
can't read appsettings.json.
I really like the new configuration system in ASP.NET Core, and am making use of it within the web app.
But is there a "simple" way to migrate these class libraries without having to rewrite them to use the new configuration system? Any basic replacement for the static ConfigurationManager.AppSettings["..."]
calls that'll read appsettings.json? (note: we'll eventually rewrite them, but we'd rather do this one piece at a time)
If you're using .NET Standard 2.0 you can add a reference to the System.Configuration.ConfigurationManager
NuGet package to get access to appSettings.
You can add an app.Config
file (not web.Config
) to your ASP.NET Core project to store the appSettings. This will be copied to the output folder and renamed as AppName.dll.config
during the project build.