How to load app.config file in DLL

Therefore, I cannot find a definitive answer to the question. How to load the app.config file into a DLL.

I understand that usually App.config information should be placed in the app.config executable. However, I am creating an add-in and have access to the executable.

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

Do you need to create code to download this file?
Can you use the ConfigurationManager namespace to make this easy?

+3
source share
2 answers

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

.NET Settings .

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

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

, assembly.dll.config . .

.

+2

Source: https://habr.com/ru/post/1736874/


All Articles