问题描述
我有一个类库,我想有一些存放在一个app.config的配置,这将被放置在同一个项目中。我试着阅读使用配置:
I have a class library and I would like to have some of the configurations stored in an App.config, which would be placed in the same project. I tried reading the configuration using:
ConfigurationManager.AppSettings [ABC];
ConfigurationManager.AppSettings["ABC"];
和它不取我的任意值。
这将是巨大的,如果可以让我知道我可以读我的App.config。我并不想这样做,使用XML。将是巨大的,如果你可以张贴在C#来代码示例。
It would be great if you can let me know how I can read my App.config. I don't want to do this using xml. Would be great if you can post come code samples in C#.
在此先感谢
推荐答案
App.config只能相关联的可执行文件。在类库谈论一个的app.config
是没有意义的。所以,你可以使用 ConfigurationManager.AppSettings [ABC];
在你的类库,但你需要的值存储在应用程序,将的应用程序/ web.config中使用这个类库。
App.config can only be associated to an executable. Talking about an app.config
in a class library makes no sense. So you could use ConfigurationManager.AppSettings["ABC"];
in your class library but you will need to store the values in the app/web.config of the application that will use this class library.
这篇关于读取类库一个app.config的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!