Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You <strong>can</strong> have separate configuration file, but you'll have to read it "manually", the <code>ConfigurationManager.AppSettings["key"]</code> will read only the config of the running assembly.</p> <p>Assuming you're using Visual Studio as your IDE, you can right click the desired project → Add → New item → Application Configuration File</p> <p><a href="https://i.stack.imgur.com/CROdR.png" rel="noreferrer"><img src="https://i.stack.imgur.com/CROdRm.png" alt="" title="click for large picture"></a> <a href="https://i.stack.imgur.com/igmeM.png" rel="noreferrer"><img src="https://i.stack.imgur.com/igmeMm.png" alt="" title="click for large picture"></a></p> <p>This will add <code>App.config</code> to the project folder, put your settings in there under <code>&lt;appSettings&gt;</code> section. In case you're not using Visual Studio and adding the file manually, make sure to give it such name: <em>DllName.dll.config</em>, otherwise the below code won't work properly.</p> <p>Now to read from this file have such function:</p> <pre><code>string GetAppSetting(Configuration config, string key) { KeyValueConfigurationElement element = config.AppSettings.Settings[key]; if (element != null) { string value = element.Value; if (!string.IsNullOrEmpty(value)) return value; } return string.Empty; } </code></pre> <p>And to use it:</p> <pre><code>Configuration config = null; string exeConfigPath = this.GetType().Assembly.Location; try { config = ConfigurationManager.OpenExeConfiguration(exeConfigPath); } catch (Exception ex) { //handle errror here.. means DLL has no sattelite configuration file. } if (config != null) { string myValue = GetAppSetting(config, "myKey"); ... } </code></pre> <p>You'll also have to add reference to System.Configuration namespace in order to have the ConfigurationManager class available.</p> <p>When building the project, in addition to the DLL you'll have <code>DllName.dll.config</code> file as well, that's the file you have to publish with the DLL itself.</p> <p>The above is basic sample code, for those interested in a full scale example, please refer to <a href="//stackoverflow.com/a/41993955/447356">this other answer</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload