用户模式 ​​.NET 设置存储在哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/469742/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 11:03:59  来源:igfitidea点击:

Where are user-mode .NET settings stored?

.netsettings

提问by Nicolas Dorier

I'm wondering what is the magic behind .settings files in .NET. Imagine you create an assembly called in this example SettingsHolder, you create your settings class which is public with a string inside in user mode , then you compile.

我想知道 .NET 中 .settings 文件背后的魔力是什么。想象一下,你创建了一个在这个例子中调用的程序集SettingsHolder,你创建了你的设置类,它在用户模式下是公共的,里面有一个字符串,然后你编译。

Now you reference your assembly in MyApp, you compile then you can change the value in your application of your setting with the settings class generated in SettingsHolderand persist them.

现在您在 MyApp 中引用您的程序集,然后进行编译,然后您可以使用生成的设置类更改应用程序中的设置值SettingsHolder并保留它们。

Now go in the output directory of MyApp and there is no trace of your setting (nothing in the application configuration file, nothing in the assembly, nothing !).

现在进入 MyApp 的输出目录,没有任何设置痕迹(应用程序配置文件中没有任何内容,程序集中没有任何内容,没有!)。

What is going on?! (I have tried to source step debug in .NET source, and reflector to see what is happening, .NET seems to use LocalFileSettingsProvider(but it seems weird to me because there is nothing in MyApp.exe.configin the output directory).

到底是怎么回事?!(我尝试在 .NET 源代码中进行步骤调试,并使用反射器查看发生了什么,.NET 似乎正在使用LocalFileSettingsProvider(但对我来说似乎很奇怪,因为MyApp.exe.config输出目录中没有任何内容)。

回答by ine

The setting files are stored in a different place for each user. To find them, click the start menu, click run, and paste:

每个用户的设置文件存储在不同的位置。要找到它们,请单击开始菜单,单击运行,然后粘贴:

%USERPROFILE%\Local Settings\Application Data\

and press enter. There will be a folder with your "Company Name" (whatever it is set to in your assembly) and then some more subfolders. The settings are stored in user.config.

并按回车键。将有一个包含您的“公司名称”的文件夹(无论在您的程序集中设置为什么),然后是更多子文件夹。设置存储在 user.config 中。

Full path:

完整路径:

%USERPROFILE%\Local Settings\Application Data\<Company Name>\
<appdomainname>_<eid>_<hash>\<verison>\user.config.

In Windows Vista and newer, these are stored under:

在 Windows Vista 和更新版本中,这些存储在:

%USERPROFILE%\AppData\Local\

More info:

更多信息:

回答by MrCalvin

On OS >= VistaI will claim the the user-setting file it's located here:

在 OS >= Vista 上,我将声明它位于此处的用户设置文件:

%LOCALAPPDATA%\ yourcompany\ app-name\ ..\user.config

%LOCALAPPDATA%\ yourcompany\ app-name\ ..\user.config

回答by Andrew Hare

The settings file is contained inside the compiled assembly.

设置文件包含在编译的程序集中。

Edit:

编辑:

Just to clarify a bit. The code to getand setthe settings from the file are compiled into the assembly. The values themselves are moved into Program.exe.configwhere Programis the name of your application. Reflector will let you see the code that gets and sets the value including the hard-coded key to the config file. The config file itself will show you the value and allow you to change it after the application has been built.

只是为了澄清一点。文件中的代码getset设置被编译到程序集中。值本身被移动到Program.exe.config哪里Program是你的应用程序的名称。Reflector 将让您看到获取和设置值的代码,包括配置文件的硬编码密钥。配置文件本身将向您显示该值,并允许您在构建应用程序后更改它。