4

我们的应用程序在运行时从应用程序的根目录加载我们的自定义 DLL(这些 DLL 正在实现某些接口)并通过反射执行方法。

如果自定义 DLL 必须从配置文件中读取一些值,那么我们必须将这些配置设置复制到主应用程序的 app.config 文件中。

有没有办法让每个自定义 DLL 都有自己的名为 .config 的配置文件,并从该文件本身读取其配置设置。

4

3 回答 3

3

If you're on .NET 2.0 or higher, you can manually tell the Configuration system to load the settings from any config file you want.

ExeConfigurationFileMap exeMap = new ExeConfigurationFileMap();
exeMap.ExeConfigFilename = "C:\Application\Default.config";

Configuration exeConfig = ConfigurationManager.OpenMappedExeConfiguration(exeMap, ConfigurationUserLevel.None);

Now you have your custom "Config" object and you can party on it! :-) Load a whole section by calling exeConfig.GetSection() or whatever you like.

Also check out this excellent three-part series on .NET 2.0 configuration system on CodeProject - highly recommended!

Marc

于 2009-04-13T13:54:05.093 回答
1

将您的 DLL 加载到新的 AppDomain 并设置 AppDomainSetup.ConfigurationFile。这将允许您为每个自定义 DLL 创建单独的配置文件。

于 2009-04-13T13:23:38.380 回答
0

I was certain there is a way to do this in the framework, just can't remember off the top of my head. What you're looking for is Per-Assembly configuration files, I remember reading an article about this Per Assembly Configuration Files

于 2009-04-13T13:26:58.810 回答