本文介绍了Visual Studio设置文件-如何工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白以下几点:

  1. app.config(applicationname.exe.config)和设置文件之间有什么区别?
  2. 我无法在Windows7 AppData目录中的特定帐户下找到* .settings文件(听说它应该位于该位置的某个位置)?
  3. 我们假设* .settings文件位于硬盘驱动器上的某个位置.为什么在开发时将设置文件中的数据复制到应用程序配置文件中?

亲切问候PK

推荐答案

因此,默认设置存储在与可执行文件位于同一目录的<exename>.config文件中.

So the default settings are stored in the <exename>.config file located in the same directory as the executable.

找不到user.config文件的原因是只有在更改默认值后才会创建该文件.用户设置将覆盖存储在<exename>.config文件中的默认设置. 如果未进行任何更改,则将不存在用户配置文件.而且...一旦存在,您将注意到只有已更改的设置才会显示在user.config文件中

The reason you do cannot find the user.config file is it is only created if you have made changes to the defaults. The user settings override the defaults which are stored in the <exename>.config file. If no changes have been made, then no user configuration file will exist. And... once it does exist you will notice that only the settings which have been changes will show up in the user.config file.

要对此进行测试,请在设置"文件中创建一个名为temp的虚拟变量.启动应用程序时,请执行以下操作:

To test this... create a dummy variable called like temp in your Settings file. When you start your application do:

Settings1.Default.temp = Settings1.Default.temp + 1;
Settings1.Default.Save();

您现在将在用户的ApplicationData文件夹中创建一个名为user.config的文件,该文件在Vista中位于:C:\Users\<username>\AppData\Local\<company>\<productname>

You will now have a file called user.config created in the user's ApplicationData folder which on Vista is in: C:\Users\<username>\AppData\Local\<company>\<productname>

这是我编写的一些代码,以帮助确定所有各种SpecialFolders在不同操作系统上的位置. (可能想为log.Debug做一个查找替换并替换为Console.WriteLine)

Here is some code I wrote to help identify where all the various SpecialFolders where on different Operating Systems. (Might want to do a find-replace for log.Debug and replace with Console.WriteLine)

log.Debug("SpecialFolder.ApplicationData: " + Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData ));
log.Debug("SpecialFolder.CommonApplicationData: " + Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData ));
log.Debug("SpecialFolder.ProgramFiles: " + Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles));
log.Debug("SpecialFolder.CommonProgramFiles: " + Environment.GetFolderPath(Environment.SpecialFolder.CommonProgramFiles ));
log.Debug("SpecialFolder.DesktopDirectory: " + Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory ));
log.Debug("SpecialFolder.LocalApplicationData: " + Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData ));
log.Debug("SpecialFolder.MyDocuments: " + Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments ));
log.Debug("SpecialFolder.System: " + Environment.GetFolderPath(Environment.SpecialFolder.System ));

在Windows Server 2003上的输出:

Output On Windows Server 2003:

SpecialFolder.ApplicationData: "C:\Documents and Settings\blake\Application Data"
SpecialFolder.CommonApplicationData: "C:\Documents and Settings\All Users\Application Data"
SpecialFolder.ProgramFiles: "C:\Program Files"
SpecialFolder.CommonProgramFiles: "C:\Program Files\Common Files"
SpecialFolder.DesktopDirectory: "C:\Documents and Settings\blake\Desktop"
SpecialFolder.LocalApplicationData: "C:\Documents and Settings\blake\Local Settings\Application Data"
SpecialFolder.MyDocuments: "C:\Documents and Settings\blake\My Documents"
SpecialFolder.System: "C:\WINDOWS\system32"

在Vista上的输出:

Output on Vista:

SpecialFolder.ApplicationData: "C:\Users\blake\AppData\Roaming"
SpecialFolder.CommonApplicationData: "C:\ProgramData"
SpecialFolder.ProgramFiles: "C:\Program Files"
SpecialFolder.CommonProgramFiles: "C:\Program Files\Common Files"
SpecialFolder.DesktopDirectory: "C:\Users\blake\Desktop"
SpecialFolder.LocalApplicationData: "C:\Users\blake\AppData\Local"
SpecialFolder.MyDocuments: "C:\Users\blake\Documents"
SpecialFolder.System: "C:\Windows\system32"

这篇关于Visual Studio设置文件-如何工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 23:34