.NET自己的配置文件自己的、配置文件、NET

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

有配置文件我想用什么办法,我可以指定在运行时(而不是其他的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);
阅读全文

相关推荐

最新文章