Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to access external .config files?

I have an asp.net mvc website which of course has a web.config file. I also have an external project which is a class library that uses a .config file for its own app settings. The problem is when I run my web application those external app settings values are not included in the appSettings.

How can I get the external class library projects appSettings values?

like image 527
chobo Avatar asked Jan 19 '23 16:01

chobo


2 Answers

You can get the external app setting like that :

    var config = ConfigurationManager.OpenExeConfiguration("some.config");
    var someKeyValue = config.AppSettings.Settings["someKey"].Value;
like image 86
Jacob Avatar answered Jan 31 '23 01:01

Jacob


You need to either:
1. add those settings to your web.config file.
2. point to the external settings, and use a post build event handler to copy the output into your web project.

<configuration>
    <appSettings configSource="my.config" />
</configuration>

Standard convention is that you add the settings to your web.config file. assemblies that are only dlls do not load their own config files. This allows people who use them to specify the settings in their own application.

like image 36
Charles Lambert Avatar answered Jan 31 '23 01:01

Charles Lambert