当一个app.config创建,当app.exe.config什么区别 [英] When is an app.config created, when an app.exe.config and what is the difference

查看:387
本文介绍了当一个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);

这里的问题是,在一些场合的应用程序创建一个应用程序名称config文件,并在其他场合的应用程序的名字名为.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.

我已经完成了测试,在同一台PC,具有完全相同的.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天全站免登陆