在.NET中从app.config或web.config读取设置

♀尐吖头ヾ 提交于 2020-07-27 08:40:47

问题:

I'm working on a C# class library that needs to be able to read settings from the web.config or app.config file (depending on whether the DLL is referenced from an ASP.NET web application or a Windows Forms application). 我正在使用一个C#类库,该类需要能够从web.configapp.config文件中读取设置(取决于DLL是从ASP.NET Web应用程序还是Windows Forms应用程序引用的)。

I've found that 我发现

ConfigurationSettings.AppSettings.Get("MySetting")

works, but that code has been marked as deprecated by Microsoft. 可以,但是该代码已被Microsoft标记为已弃用。

I've read that I should be using: 我读过我应该使用:

ConfigurationManager.AppSettings["MySetting"]

However, the System.Configuration.ConfigurationManager class doesn't seem to be available from a C# Class Library project. 但是,C#类库项目中似乎没有System.Configuration.ConfigurationManager类。

What is the best way to do this? 做这个的最好方式是什么?


解决方案:

参考一: https://stackoom.com/question/4zPI/在-NET中从app-config或web-config读取设置
参考二: https://oldbug.net/q/4zPI/Reading-settings-from-app-config-or-web-config-in-NET
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!