.NET自己的配置文件 [英] .NET own configuration file

查看:122
本文介绍了.NET自己的配置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有配置文件我想用什么办法,我可以指定在运行时(而不是其他的App.config)?比如我想读一个在命令行第一个参数,这将是一个应用程序路径的配置,我想我的应用程序引用它,当我使用ConfigurationManager.AppSettings(这可能是不可能的,但它仍然是值得一问)。
我没有找到这片code:

Is there any way that I could specify at runtime the configuration file I would like to use (other than App.config)? For example I would like to read a first argument from a command line that will be a path to the application's config and I would like my application to refer to it when I use ConfigurationManager.AppSettings (It's probably impossible but still it's worth asking).
I did find this piece of code:

System.Configuration.Configuration config
    = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
        config.AppSettings.File = myRuntimeConfigFilePath;
        config.Save(ConfigurationSaveMode.Modified);
        ConfigurationManager.RefreshSection("appSettings");

它的工作原理,但它会覆盖原来的App.config的AppSettings的部分和我的应用程序不应该写什么。

It works, but it overrides the original App.config's AppSettings section and my application isn't supposed to write anything.

推荐答案

我发现这和它的作品。 路径是一个路径配置文件。

I found this and it works. "path" is a path to configuration file.

AppDomain.CurrentDomain.SetData("APP_CONFIG_FILE", path);

这篇关于.NET自己的配置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆