Reading dll.config (not app.config!) from a plugin module

前端 未结 2 1378
不知归路
不知归路 2020-11-30 05:08

I am writing a C# .NET 2.0 .dll that is a plug in to a Larger application. The visual studio project for my module has a app.config file which is copied to a MyProj.dll.con

2条回答
  •  自闭症患者
    2020-11-30 05:24

    You will need to load the x.dll.config (with the Configuration API) yourself. All the automatic file handling (including the .Settings) is all about machine.config/y.exe.config/user-settings.

    To open a named config file:

    • Reference System.Configuration.dll assembly.
    • Using System.Configuration
    • Create code like:

      Configuration GetDllConfiguration(Assembly targetAsm) {
        var configFile = targetAsm.Location + ".config";
        var map = new ExeConfigurationFileMap {
          ExeConfigFilename = configFile
        };
        return ConfigurationManager.OpenMappedExeConfiguration(map, ConfigurationUserLevel.None);
      }
      

提交回复
热议问题