开发者

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

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.

开发者_JAVA百科

Do you need to build out some code to load this file in?

Can you use the configurationManager namespace to make this happen easily?


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 );
}


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜