如何读取app.config在dll级别。 [英] How to read app.config at dll level.?

查看:175
本文介绍了如何读取app.config在dll级别。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个控制台应用程序项目和库项目(dll)在一个解决方案。

I have a console application project and library project (dll) in one solution.

库项目有一个app.config文件,其中存储了我在库中使用的一些键值对。控制台应用程序引用此dll。

The library project has app.config file where I store some key value pair that I use in library. The console application references this dll.

我在控制台应用程序中有另一个app.config文件,其中有控制台应用程序的设置。

I have another app.config file at console application where I have settings for console application.

当我运行程序时, library.dll 总是指向控制台应用程序 app.config

When I run the program my library.dll always refers app.config from console application.

我想分离每个dll的责任,所以我想要一个dll始终引用其自己的 app.config文件而不是调用应用程序。

I want to separate the responsibility of each dll, so I want a dll to always refer to its own app.config file not that of the calling application.

在这种情况下, library.dll 应使用自己的app.config,

In this case library.dll should use app.config of its own, not of the calling application.

推荐答案

您要求的内容已多次被多次提出...

What you are asking has been asked many times again and again...

实际上,您可以指示.NET从另一个文件读取配置设置,类似library.dll.config,有项目或类,这样做是类似assemblysettingsreader或类似的东西。

in fact you could instruct .NET to read configuration settings from another file, in your case will be something like library.dll.config, there are projects or classes to do this called something like assemblysettingsreader or similar.

我的建议是反正不要这样做。这听起来很酷最初,但认为这样,你的库不是独自运行,可以通过控制台应用程序,网站或wpf ui项目,所有这些客户端可能需要自定义配置和有不同的设置,使它完全感觉有与调用应用程序配置文件相关的设置。

My suggestion is anyway to do not do it. It sounds cool initially but think in this way, your library is not running alone, can be referenced by a console app, a web site or a wpf ui project, all these clients might need to customize the configuration and have different settings so it makes full sense to have the settings related to the calling application config files.

这篇关于如何读取app.config在dll级别。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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