app.config是什么时候创建的,app.exe.config什么时候创建,有什么区别 [英] When is an app.config created, when an app.exe.config and what is the difference

查看:41
本文介绍了app.config是什么时候创建的,app.exe.config什么时候创建,有什么区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们已经创建了一个 WinForms 应用程序并通过 ConfigurationManager 类存储了一些配置.为了存储我使用的信息

We have created a WinForms application and store some configurations via the ConfigurationManager class. In order to store the information I use

Configuration pConfig = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
pConfig.AppSettings.Settings.Add("updates", szUpdatesURL);
pConfig.Save(ConfigurationSaveMode.Modified);

这里的问题是,在某些情况下,应用程序会创建appname".config 文件,而在其他情况下会创建appname".exe.config.

The problem here is that in some occasions the application creates an "appname".config file and in other occasions an "appname".exe.config.

在这里我必须注意,默认情况下不提供配置文件,因为它并不总是必需的.

第一次执行程序时保存配置.这给我们带来了一个问题,我无法指定创建哪一个的时机.

The configurations are saved the first time the program is executed. This has caused us a problem, and I cannot specify the occasions when which one or the other is created.

我在同一台电脑上使用完全相同的 .exe 执行了测试,我得到了两个结果.这里发生了什么?

I have performed the tests, on the same pc, with the exact same .exe and I get both results. What's going on here?

两者有什么区别,如何指定应该创建哪一个?非常感谢

What is the difference between the two, and how can I specify which one should be created? Many thanks

推荐答案

当您编译应用程序时,会自动为您创建appname.exe.config".这是应该分发给最终用户的文件(当然还有 exe 文件).您在 appname.config 中设置的设置将转移到 appname.exe.config.它们本质上是相同的文件.appname.config 存在的原因是因为当可执行文件运行时,它的配置文件很简单,就是带有 .config 后缀的可执行文件的名称.但是,如果可执行文件的名称已更改,则必须手动更改 exe.config 文件的名称.因此,通过在编译时自动重命名,app.config 可以将其名称更改为 newappname.exe.config 文件,而 CLR 仍会选择它.您可能会发现 appname.exe.config 文件是在 bin 目录中创建的.我希望这很清楚:) 下面的链接可能会更深入地解释它.

The "appname.exe.config" is automatically created for you when you compile your application. This is the file that should be distributed to your end users (along with the exe file, of course). The settings you set in appname.config is transferred over to appname.exe.config. They are essentially the same files. The reason appname.config exists is because when the executable is run, it's config file is simple the executable's name with a .config suffix. However, if the executable's name changed, you would have to change the name of the exe.config file manually. Therefore, by automatically renaming at compile time, the app.config can change it's name to newappname.exe.config file and the CLR will still pick it up. You'll probably find that the appname.exe.config file is created in the bin directory. I hope that's clear :) The links below may explain it in slightly more depth.

有一个很好的解释这里.另一个不错的读物是 CodePlex.

There's a good explanation here. Another good read is on CodePlex.

这篇关于app.config是什么时候创建的,app.exe.config什么时候创建,有什么区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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