在.NET中从app.config或web.config读取设置 - Reading settings from app.config or web.config in .NET

问题:

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应用程序引用的)。 web

I've found that 我发现 app

ConfigurationSettings.AppSettings.Get("MySetting")

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

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

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类。 spa

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


解决方案:

参考一: 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
相关文章
相关标签/搜索