Visual Studio - 查找exe.config文件 [英] Visual Studio - Locating exe.config file

查看:86
本文介绍了Visual Studio - 查找exe.config文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景



我决定第一次尝试使用Visual Studio支持配置文件。



在Project-> Properties->设置中我创建了一堆带有User范围的应用程序设置,以便我可以在运行时更改它们。



这样工作正常,但我注意到当我在Visual Studio环境中运行程序时,它使用的配置文件与在VS之外的可执行文件运行时不同。我无法找到对此负责的文件!



示例:

其中一个设置称为EngineerPassword。

如果我在Visual Studio中调试应用程序,然后在运行时将EngineerPassword更改为hello,当我停止调试并再次开始调试时,此设置仍然存在。

如果我然后停止调试,我直接运行可执行文件,我发现密码不是你好。我可以把它设置为:让我说我把它设置为世界。现在,当我在Visual Studio中运行应用程序时,EngineerPassword仍然是hello,当我运行可执行文件时,它就是世界。很明显,它在这些场景中使用单独的配置文件。



在应用程序文件夹结构中有一个名为app.config的文件,但它包含的默认设置是我最初创建设置时到位。在运行时更改设置时,它不会更改。

此外,还有一个exe.config文件与可执行文件位于同一文件夹中。当我更改设置时,这不会改变。



问题:



设置新设置时哪些文件正在更改?它们位于何处?

BACKGROUND

I've decided to try using the Visual Studio support for configuration files for the first time.

In Project->Properties->Settings I have created a bunch of application settings with the "User" scope so that I can change them at run-time.

This is working OK, but I notice that when I run the program within the Visual Studio environment, it uses a different config file than when it runs as an executable outside of VS. I can't locate either of the files responsible for this!

Example:
One of the settings is called "EngineerPassword".
If I debug the application in Visual Studio and then, at run time, I change the EngineerPassword to "hello", this setting persists when I stop debugging and start debugging again.
If I then stop debugging, and I run the executable directly, I find that the password is not "hello". I can set it to something: let's say I set it to "world". Now, when I run the application inside Visual Studio the EngineerPassword is still "hello", and when I run the executable it is "world". So clearly it is using separate config files in these scenarios.

Inside the application folder structure there is a file called app.config, but this contains the default settings which were in place when I initially created the Settings. It does not change when I change the settings at runtime.
Additionally there is an exe.config file located in the same folder as the executable. This does not change when I change the settings either.

THE QUESTION:

Which files are changing when I set new settings? Where are they located?

推荐答案

用户范围的设置存储在此处(在Win7上):



C:\ Users \ 用户 \ AppData \本地\ 公司 \ appname + somerandomcharacters



根据此CodeProject文章:



.NET配置文件的原因,位置和方式 [ ^ ]
The settings for user scope are stored here (on Win7):

C:\Users\user\AppData\Local\company\appname+somerandomcharacters

As per this CodeProject Article:

Why, Where, and How of .NET Configuration Files[^]


这些设置以某种方式缓存。



在代码中bef你读取你的设置的代码放置代码行:

These settings are cached somehow.

In the code before you read your settings place the code line:
Properties.Settings.Default.Reload();





玩得开心CODING



Have fun CODING


从Visual Studio运行时,它可能会使用 ProgName.vshost.exe.config 而不是 ProgName.exe.config



参见支持流程(vshost.exe)
When running from Visual Studio, it might use the ProgName.vshost.exe.config and not the ProgName.exe.config.

See Hosting Process (vshost.exe)


这篇关于Visual Studio - 查找exe.config文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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