如何使DLL具体配置文件? [英] How to have DLL specific config file?
问题描述
请帮忙解决这个问题。还有,是否有可能?
如果您可以提供一个小的代码示例,我将非常有帮助。
是的,这是可能的。就像你可以有exe.config文件,它完全正常有一个dll.config文件。在其配置文件中存储DLL特定信息。稍后,您可以通过以下代码访问DLL中的配置信息:
var appConfig = ConfigurationManager.OpenExeConfiguration(Assembly.GetExecutingAssembly())。位置);
string dllConfigData = appConfig.AppSettings.Settings [dllConfigData]。
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.
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;
这篇关于如何使DLL具体配置文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!