在.NET中从app.config或web.config阅读设置
在.NET中从app.config或web.config阅读设置
我正在开发一个C#类库,需要能够从web.config
或app.config
文件中读取设置(取决于该DLL是从ASP.NET Web应用程序还是从Windows应用程序引用的)。
我发现
ConfigurationSettings.AppSettings.Get("MySetting")
有效,但是该代码已经被Microsoft标记为不推荐使用。
我已经阅读过应该使用以下代码:
ConfigurationManager.AppSettings["MySetting"]
然而,在一个C#类库项目中,System.Configuration.ConfigurationManager
类似乎不可用。
最好的方法是什么?
admin 更改状态以发布 2023年5月23日