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?
(做这个的最好方式是什么?)
ask by Russ Clark translate from so 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…