开发者

Finding app config file from assembly

开发者 https://www.devze.com 2023-03-20 03:58 出处:网络
I\'m using Nini to read config throughout the app. I\'m running into a problem in assemblies where I want to read the main applications config file (regardless of web.config or app.config).

I'm using Nini to read config throughout the app. I'm running into a problem in assemblies where I want to read the main applications config file (regardless of web.config or app.config).

This is standard way:

private static IConfigSource source = new DotNetConfigSource(DotNetConfigSource.GetFullConfigPath());

The problem in the case of a开发者_JAVA技巧ssemblies is that DotNetConfigSource.GetFullConfigPath() returns "assembly.dll.config", not "app.exe.config" or "web.config".

What to do, what to do?


System.Configuration.Configuration config =
                ConfigurationManager.OpenExeConfiguration(
                ConfigurationUserLevel.None);

string configPath = config.FilePath;

private static IConfigSource source = new DotNetConfigSource(configPath);

Try that.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号