本文介绍了使用的app.config一个类库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常需要创建一个.NET类库,需要一个app.config的东西,如数据库连接字符串。但是,这些设置必须在调用应用程序的的app.config或web.config中。如果我要分发在多个应用程序就变成了DLL一个痛苦保持应用程序的App.config中复制这些设置。

Frequently I need to create a .Net class library that requires an app.config for things such as database connection strings. However, these settings must be in the calling application's app.config or web.config. If I want to distribute the DLL across multiple applications it becomes a pain to have to keep copying these settings in the application's app.config.

我已经手动考虑读通过类库里面code的配置设置,但是这也是一个重大的痛苦。没有人有任何建议的最佳方式来加载的app.config设置里面一个类库?

I have considered manually reading the config settings via code inside the class library, but that is also a major pain. Does anyone have any suggestions for the best way to load app.config settings inside a class library?

推荐答案

有一件事情你可以做的是有一个单独的设置文件只为您的图书馆,那么你只需要拥有一提到它在您的输入应用程序的配置文件

One thing you could do is to have a seperate settings file just for your library, then you only have to have a reference to it in your entry apps config file.

见accepted在 href="http://stackoverflow.com/questions/396139/create-your-own-settings-in-xml">这个问题了解这些信息。

See the accepted answer in this question for information on this.

这篇关于使用的app.config一个类库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 00:21