简体   繁体   中英

How can I get assembly.dll.config file?

如何在.net中正在执行的应用程序的容器中获取Assembly.dll.config?

Attach a config file for a .NET library (dll) is not a good approach. What if this dll is installed into GAC? Where is the config file supposed to be loaded? All settings are recommended to be stored in app.config for the executable.

ConfigurationManager Class ???

String strPath = System.IO.Path.GetDirectoryName( System.Reflection.Assembly.GetExecutingAssembly().CodeBase);

I have used the following code in the past to get the config file as an XmlDocument (Please note that this assumes the '.config' extension on the config file):

System.Reflection.Assembly asm = System.Reflection.Assembly.GetCallingAssembly();
string cfgFile = asm.CodeBase + ".config";
System.Xml.XmlDocument doc = new XmlDocument();
doc.Load(new XmlTextReader(cfgFile));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM