code

.NET에서 Settings.settings 파일을 사용할 때 구성은 실제로 어디에 저장됩니까?

codestyles 2020. 8. 30. 08:38
반응형

.NET에서 Settings.settings 파일을 사용할 때 구성은 실제로 어디에 저장됩니까?


.NET에서 Settings.settings 파일을 사용할 때 구성은 실제로 어디에 저장됩니까? 기본 상태로 돌아 가기 위해 저장된 설정을 삭제하고 싶지만 저장 위치를 ​​찾을 수 없습니다. 아이디어가 있습니까?


선택한 설정이 "사용자"범위인지 "응용 프로그램"범위인지에 따라 다릅니다.

사용자 범위

사용자 범위 설정은

C : \ Documents and Settings \ 사용자 이름 \ Local Settings \ Application Data \ ApplicationName

런타임에 읽고 쓸 수 있습니다.

Vista 및 Windows 7의 경우 폴더는

C : \ Users \ 사용자 이름 \ AppData \ Local \ ApplicationName

또는

C : \ Users \ 사용자 이름 \ AppData \ Roaming \ ApplicationName

적용 범위

애플리케이션 범위 설정은에 저장 AppName.exe.config되며 런타임시 읽기 전용입니다.


다음은 user.config 파일 위치를 프로그래밍 방식으로 가져 오는 데 사용할 수있는 스 니펫입니다.

public static string GetDefaultExeConfigPath(ConfigurationUserLevel userLevel)
{
  try
  {
    var UserConfig = ConfigurationManager.OpenExeConfiguration(userLevel);
    return UserConfig.FilePath;
  }
  catch (ConfigurationException e)
  {
    return e.Filename;
  }
}

ApplicationSettings (예 : settings.settings)는 기본적으로 사용자 설정에 PerUserRoamingAndLocal을 사용합니다 (내가 기억 한대로).

업데이트 : 이상하지만 여기에 오답이 너무 많습니다. 사용자 범위 설정 파일 (user.config)을 찾는 경우 다음 폴더 (Windows XP의 경우)에 있습니다.

C : \ Documents and Settings \ (사용자 이름) \ Local Settings \ Application Data \ (company-name-if-exists) \ (앱 이름) .exe_ (Url | StrongName) _ (해시) \ (앱 버전) \

Url 또는 StrongName은 애플리케이션 어셈블리 강력한 이름 여부에 따라 다릅니다.


웹 애플리케이션이 아닌 데스크톱에 대해 이야기한다고 가정합니다.

프로젝트에 설정을 추가하면 VS는 app.config프로젝트 디렉터리에 이름이 지정된 파일을 만들고 해당 파일 에 설정을 저장합니다. 또한 Settings.cs개별 설정에 대한 정적 접근자를 제공 하는 파일을 빌드합니다 .

컴파일 타임에 VS는 (기본적으로 이것을 변경할 수 있습니다) app.config를 빌드 디렉터리에 복사 하여 실행 파일과 일치하도록 이름을 변경합니다 (예 : 실행 파일 이름 foo.exe이이면 파일 foo.exe.config이름이. NET 구성 관리자는 런타임에 설정을 검색하는시기를 찾습니다.

VS 설정 편집기를 통해 설정을 변경하면 app.configSettings.cs. (에서 생성 된 코드의 속성 접근 Settings.cs자를 보면 app.config파일 에있는 설정의 기본값을 포함하는 속성으로 표시되어 있음을 알 수 있습니다.) app.config파일을 직접 편집하여 설정을 변경하는 경우 , Settings.cs업데이트되지 않지만 새 값은 컴파일 타임에 app.config복사 되기 때문에 프로그램을 실행할 때 프로그램에서 계속 사용됩니다 foo.exe.config. 이 기능을 끄면 (파일 속성 설정) foo.exe.config빌드 디렉토리에서 파일 을 직접 편집하여 설정을 변경할 수 있습니다 .

그런 다음 사용자 범위 설정이 있습니다.

응용 프로그램 범위 설정은 읽기 전용입니다. 프로그램은 사용자 범위 설정을 수정하고 저장할 수 있으므로 각 사용자가 자신의 설정을 가질 수 있습니다. 이러한 설정은 foo.exe.config파일에 저장되지 않습니다 (최소한 Vista에서는 프로그램이 Program Files권한 상승없이의 하위 디렉터리에 쓸 수 없기 때문에 ). 사용자의 애플리케이션 데이터 디렉토리에있는 구성 파일에 저장됩니다.

해당 파일의 경로는 %appdata%\%publisher_name%\%program_name%\%version%\user.config, 예를 C:\Users\My Name\AppData\Local\My_Company\My_Program.exe\1.0.0\user.config. 프로그램에 강력한 이름을 지정한 경우 강력한 이름이이 경로의 프로그램 이름에 추가됩니다.


폴더 이름의 해시를 알아 내기 위해 둘러 보는 동안 ( 이 답변을 통해 ) 발견했습니다.

http://blogs.msdn.com/b/rprabhu/archive/2005/06/29/433979.aspx

(edit: Wayback Machine link: https://web.archive.org/web/20160307233557/http://blogs.msdn.com:80/b/rprabhu/archive/2005/06/29/433979.aspx)

The exact path of the user.config files looks something like this:

<Profile Directory>\<Company Name>\<App Name>_<Evidence Type>_<Evidence Hash>\<Version>\user.config

where

<Profile Directory> - is either the roaming profile directory or the local one. Settings are stored by default in the local user.config file. To store a setting in the roaming user.config file, you need to mark the setting with the SettingsManageabilityAttribute with SettingsManageability set to Roaming.

<Company Name> - is typically the string specified by the AssemblyCompanyAttribute (with the caveat that the string is escaped and truncated as necessary, and if not specified on the assembly, we have a fallback procedure).

<App Name> - is typically the string specified by the AssemblyProductAttribute (same caveats as for company name).

<Evidence Type> and <Evidence Hash> - information derived from the app domain evidence to provide proper app domain and assembly isolation.

<Version> - typically the version specified in the AssemblyVersionAttribute. This is required to isolate different versions of the app deployed side by side.

The file name is always simply 'user.config'.


Erm, can you not just use Settings.Default.Reset() to restore your default settings?


It is in a folder with your application's name in Application Data folder in User's home folder (C:\documents and settings\user on xp and c:\users\user on Windows Vista).

There is some information here also.

PS:- try accessing it by %appdata% in run box!


All your settings are stored in the respective .config file.

The .settings file simply provides a strongly typed class for a set of settings that belong together, but the actual settings are stored in app.config or a .config file in your application.

If you add a .settings file, an app.config will be automatically added to house the settings if you don't already have one.


If your settings file is in a web app, they will be in teh web.config file (right below your project. If they are in any other type of project, they will be in the app.config file (also below your project).

Edit

As is pointed out in the comments: your design time application settings are in an app.config file for applications other than web applications. When you build, the app.config file is copied to the output directory, and will be named yourexename.exe.config. At runtime, only the file named yourexename.exe.config will be read.


Two files: 1) An app.config or web.config file. The settings her can be customized after build with a text editer. 2) The settings.designer.cs file. This file has autogenerated code to load the setting from the config file, but a default value is also present in case the config file does not have the particular setting.


I know it's already answered but couldn't you just synchronize the settings in the settings designer to move back to your default settings?

참고URL : https://stackoverflow.com/questions/1075204/when-using-a-settings-settings-file-in-net-where-is-the-config-actually-stored

반응형