问题描述
我的工作,需要能够读取设置了的web.config
或的app.config 文件(取决于该DLL是从ASP.NET Web应用程序中引用或Windows窗体应用程序)。
I'm working on a C# class library that needs to be able to read settings 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).
我发现,
ConfigurationSettings.AppSettings.Get("MySetting")
工作,但code已被标记为微软pcated德$ P $。
works, but that code has been marked as deprecated by Microsoft.
我读过,我应该使用:
ConfigurationManager.AppSettings["MySetting"]
不过,
System.Configuration.ConfigurationManager
类似乎没有可以从一个C#类库项目。
However, the
System.Configuration.ConfigurationManager
class doesn't seem to be available from a C# Class Library project.
有谁知道做到这一点的最好办法是?
Does anyone know what the best way to do this is?
推荐答案
您需要添加引用到
System.Configuration
的项目的引用文件夹。
您绝对应该使用
ConfigurationManager中
在过时的 ConfigurationSettings
。
You should definitely be using the
ConfigurationManager
over the obsolete ConfigurationSettings
.
这篇关于阅读在.net中的的app.config或web.config设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!