How to have DLL specific config file?

2019-07-31 10:01发布

I wish to have multiple config files in my solution. For example, For my console application (Program.Main) I want to refer app.config file for any settings. While my console application internally calls a method of a class libray Dll1. Inside Dll1 I want the code to take some settings from Dll1.config. Similarly my Console application also calls a method of Dll2. Inside Dll2 I want the code to take settings from Dll2.config file.

Please help on how to achieve this. Also, is it possible or not? I would be really helpful if you could provide with a small code sample.

标签: c# dll config
1条回答
唯我独甜
2楼-- · 2019-07-31 10:34

Yes, it is possible. Just like you can have exe.config file, its perfectly normal to have a dll.config file. Store DLL specific information in its config file. Later on you can access this configuration information from DLL by following code

var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly().Location);
string dllConfigData = appConfig.AppSettings.Settings["dllConfigData"].Value;
查看更多
登录 后发表回答