问题描述
我有引用项目B的项目A.如果项目A调用项目B,项目B调用ConfigurationManager.GetSection().它将从项目A的App.Config中获取设置.有什么方法可以从项目B的app.config中获取设置.我希望措辞不要太混乱.我是C#和编程的新手.我试图用谷歌搜索,但不确定如何定义问题.如果需要的话,我会澄清.谢谢.
I have project A referencing project B. If project A calls project B and project B calls ConfigurationManager.GetSection(). It''ll get the settings from project A''s App.Config. Is there any way to get the settings from project B''s app.config. I hope the wording''s not too confusing. I''m new to C# and programming. I tried to google but not sure how to define the problem. I''ll clarify things if need be. Thank you.
推荐答案
string exeName = typeof(MyType).Assembly.Location;
使用此可执行文件的名称传递给对System.Configuration.ConfigurationManager.OpenExeConfiguration
的调用.如果使用某些其他应用程序主机,则其他所有获取可执行文件名称的方法都可能会失败,例如,Visual Studio或服务" Windows服务.
Use this executable name to pass to the call to System.Configuration.ConfigurationManager.OpenExeConfiguration
. All other ways of getting executable name may fail if some different application host is used, for example, Visual Studio or ''Services'' Windows service.
这篇关于从app.config获取设置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!