How do you load the app.config file into a DLL

我是研究僧i 提交于 2019-12-07 16:14:16

问题


So I cant find a definitive answer to the Question. How do you load the app.config file into a DLL.

I understand that generally the App.config info should be put into the executable app.config. However i am building an add-in and have to executable available.

I would like to use the namespace.dll.config file to store my variables, but i need a way of loading it into the system.

Do you need to build out some code to load this file in?
Can you use the configurationManager namespace to make this happen easily?


回答1:


This example will load any *.config file from your bin directory as a new configuration object.

Alternatively, .NET Settings will automatically compile the default into the assembly.

public Configuration DllConfiguration( string filename )
{
    var map = new ExeConfigurationFileMap {
         ExeConfigFilename = Path.Combine( AppDomain.CurrentDomain.BaseDirectory, filename )
    };

    return ConfigurationManager.OpenMappedExeConfiguration( map, ConfigurationUserLevel.None );
}



回答2:


The way this is done is that you should supply your assembly.dll.config to consumers of your assembly. They should then incorporate those entries into their application's config file.

Your assembly will then be able to access those values through normal means.



来源:https://stackoverflow.com/questions/2441858/how-do-you-load-the-app-config-file-into-a-dll

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!