My.Settings 保存在 VB 2010 .NET 中的什么位置?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8691858/
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 16:09:10  来源:igfitidea点击:

Where are My.Settings saved in VB 2010 .NET?

.netvb.netmy.settings

提问by Florian Müller

Are My.Settingsvalues saved in the program itself or do they get stored in the registry? So, for example, if I set a My.Settingsvalue with a program, then I copy the program itself to another PC - is the My.Settingsvalue still set?

My.Settings值保存在程序本身,还是他们获取存储在注册表中?因此,例如,如果我My.Settings用程序设置了一个值,然后我将程序本身复制到另一台 PC - 该My.Settings值是否仍然设置?

回答by adatapost

It depends upon the scopeyou have selected. There are two scope settings - Application and User scope.

这取决于您选择的范围。有两个范围设置 - 应用程序和用户范围。

From MSDN article:

来自 MSDN 文章:

Application-scoped settingsare read-only and are shared between all users of that application. These settings are stored in the app.config file in the section. At run time, the app.config file will be in your bin folder and will be named with your application's name (MySettingsDemo.exe.config).

User-scope settingsare specific for each user. They can be read and set safely by the application code at run time. These settings are stored in a user.config file. To be technically accurate, there are two user.configs per user per application—one for non-roaming and one for roaming. Although the Visual Basic 2005 documentation states that the user.config file will be named according to the user's name (joe.config), this is not the case. The user.config file is created in the:

应用程序范围的设置是只读的,并在该应用程序的所有用户之间共享。这些设置存储在 app.config 文件部分中。在运行时,app.config 文件将位于您的 bin 文件夹中,并以您的应用程序名称 (MySettingsDemo.exe.config) 命名。

用户范围设置特定于每个用户。它们可以在运行时由应用程序代码安全地读取和设置。这些设置存储在 user.config 文件中。从技术上讲,每个应用程序的每个用户有两个 user.configs - 一个用于非漫游,一个用于漫游。尽管 Visual Basic 2005 文档指出 user.config 文件将根据用户名 (joe.config) 命名,但事实并非如此。user.config 文件在以下位置创建:

<c:\Documents and Settings>\<username>\[LocalSettings\]ApplicationData\<companyname>\<appdomainname>_<eid>_<hash>\<verison>.

回答by Axel Esquivel

Dim config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.PerUserRoamingAndLocal)
MessageBox.Show(config.FilePath)

回答by Kishore Kumar

If you have installed your application using clickonce then your MySettings will be stored in a config file which is stored at `C:\Users\\AppData\Local\Apps\2.0\Data........

如果您使用 clickonce 安装了应用程序,那么您的 MySettings 将存储在一个配置文件中,该文件存储在`C:\Users\\AppData\Local\Apps\2.0\Data........

search in these path with a file named as yourapp.exe.config

使用名为 yourapp.exe.config 的文件在这些路径中搜索

The thing is MySettings will be stored in app.config file of that application and after publishing the app.config file is saved as applicationname.exe.config file

事情是 MySettings 将存储在该应用程序的 app.config 文件中,发布后 app.config 文件将保存为 applicationname.exe.config 文件

回答by Ry-

They're definitely not stored within the program if they're User settings - that's not very easy to implement, and rather pointless. Rather, they're stored in a configuration file in the %AppData% folder. So no, if you copied the program, the User settings wouldn't come with it, just the Application settings.

如果它们是用户设置,它们肯定不会存储在程序中——这不是很容易实现,而且毫无意义。相反,它们存储在 %AppData% 文件夹中的配置文件中。所以不,如果你复制了程序,用户设置不会随之而来,只有应用程序设置。