问题:
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.config
或app.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
来源:oschina
链接:https://my.oschina.net/u/4432649/blog/4330676