Skip to content

Commit 69103ab

Browse files
Use CurrentConfiguration before ConfigurationManager when reading parameter values from AppSettings. (#216)
1 parent c438383 commit 69103ab

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

src/Base/KeyValueConfigBuilder.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,17 @@ protected string UpdateConfigSettingWithAppSettings(string configName)
215215
});
216216
}
217217

218+
// Try to use CurrentConfiguration before falling back to ConfigurationManager. Otherwise OpenConfiguration()
219+
// scenarios won't work because we're looking in the wrong processes AppSettings.
220+
else if (CurrentSection?.CurrentConfiguration?.AppSettings is AppSettingsSection currentAppSettings)
221+
{
222+
configValue = Regex.Replace(configValue, _tokenPattern, (m) =>
223+
{
224+
string settingName = m.Groups[1].Value;
225+
return (currentAppSettings.Settings[settingName]?.Value ?? m.Groups[0].Value);
226+
});
227+
}
228+
218229
// All other config sections can just go through ConfigurationManager to get app settings though. :)
219230
else
220231
{

0 commit comments

Comments
 (0)