阅读在.net中的的app.config或web.config设置 [英] Reading settings from app.config or web.config in .net

查看:202
本文介绍了阅读在.net中的的app.config或web.config设置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的工作,需要能够读取设置了的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设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆