General configuration between .exe and .dll

I am trying to work with settings.settings file in my project. There are values ​​that must be shared between the .exe file and the various DLLs. I would prefer not only to pass these values, I would like to access them when I need it, but each project sets its values ​​with slightly different names and, therefore, is not available for other projects.

Is there a way to share the contents of the app.config file between .exe and .dll using the settings.settings approach? Or do I need to return to using ConfigurationManager for this?

+5
source share
1 answer

App.config DLL. , , dll /config, dll .

, DLL . , .

  private string GetSettingValue(string key)
  {
     string executingAssembly = Assembly.GetEntryAssembly().GetName().Name;
     string sectionName = "applicationSettings/" + executingAssembly 
                                                 + ".Properties.Settings";
     ClientSettingsSection section =
            (ClientSettingsSection)ConfigurationManager.GetSection(sectionName);

     // add null checking etc
     SettingElement setting = section.Settings.Get(key); 
     return setting.Value.ValueXml.InnerText;
  }

, dll , . .

+5

All Articles