Каково различие между app.config файлом и файлом XYZ.settings?

Пока никто не упомянул SQL. Он имеет то, что вы предлагаете:

SELECT
    employee_id
FROM 
    employee
WHERE
    hire_date BETWEEN '2009-01-01' AND '2010-01-01' -- range of values
    AND employment_type IN ('C', 'S', 'H', 'T')     -- list of values
71
задан Bart Kiers 10 November 2009 в 08:42
поделиться

3 ответа

UPDATE: In ASP.NET Core Land, configuration is no longer managed via either of these - see this fantastic writeup from Travis Illig with the a-z on Microsoft.Extension.Configuration and Microsoft.Extensions.Configuration.Binder which are effectively a superset of all this


Settings (Both from a .settings set and Configuration.AppSettings), are stored in the .config file [alongside lots of other stuff].

The difference is that the .settings stuff [which was added in .NET 2.0 / VS2005] layers a strongly typed class on top of a set of settings that belong together whereas Configuration.AppSettings just lets you retrieve strings, forcing you to do any conversions, and doesnt have the notion of defaults. (the Configuration class has actually been shunted into a side assembly to reflect this - you need to add a reference to System.Configuration explicitly if you want it).

Adding a .settings to your project will result in an app.config being added to house the settings if you dont already have one. The class which reads the settings is automatically generated each time you change the list of settings for your component/application.

Other features of .Settings is the ability to designate some settings as user-specific (and also to save the user-specific settings with a single call).

The best reason of all to use .Settings is generally that you gain the ability to clearly identify who is using which setting in a code base by following usages of properties (and each set is a separate block in the XML file). Configuration.appSettings is more global in it's nature - it's just a bag of properties and you dont know which DLL, subsystem or class depends on a particular setting entry. See this blog post from Steven Smith for much more.

Finally, if you still haven't read enough about settings management, you're not going to beat this Rick Strahl post on the subject for completeness or sheer quantities of ideas and angles.

ASIDE: There's also the ASP.NET vNext Configuration stuff, outlined in this article which is quite flexible and offers a different angle on configuration settings management.

54
ответ дан 24 November 2019 в 13:08
поделиться

Файл настроек - это файл ресурсов, в котором вы указываете различные настройки и их значения по умолчанию.

Сами значения настраиваются в файле конфигурации приложения (файл .config).

Файл настроек никогда не развертывается, поэтому для настройки вам потребуется файл конфигурации.

5
ответ дан 24 November 2019 в 13:08
поделиться

Файл app.config хранится в том же каталоге, что и приложение. У обычных пользователей не будет прав на запись (например, в «Program Files»).

Файл настроек должен храниться в папке пользователя "AppData" (где у него есть права чтения/записи).

Поэтому используйте файл настроек для настраиваемых пользователем параметров.

0
ответ дан 24 November 2019 в 13:08
поделиться
Другие вопросы по тегам:

Похожие вопросы: