Is there a way to have several hierarchies within the config file using configSource?
-
23-03-2021 - |
Question
I wonder if there is a way or a workaround to have the config files in the following structure:
App.Config
<configuration>
<appSettings configSource="AppSett.config">
<add key="test1" value="test2"/>
</appSettings>
</configuration>
and my AppSett.config will look like:
<appSettings>
<add key="test3" value="test3"></add>
</appSettings>
Solution
No, you cannot use external file with partial info to link instead of the default config structure. Config files are special files that conform to config schema and this you cannot use them in the scenario you described.
OTHER TIPS
Yes, that's what configSource is for, but the configuration section can have content or configSource attribute, not both.
You can implement this approach by using file
attribute instead of configSource
:
- http://msdn.microsoft.com/en-us/library/aa903313(v=vs.71).aspx
- http://www.codeproject.com/KB/dotnet/appsettings_fileattribute.aspx
In your example, you should have file App.Config
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings configSource="AppSett.config">
<add key="test1" value="test2"/>
</appSettings>
</configuration>
and AppSett.config
<?xml version="1.0" encoding="utf-8" ?>
<appSettings>
<add key="test3" value="test3"></add>
</appSettings>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow