What is the Windows RT / Windows Store App answer

2019-01-18 02:52发布

问题:

What is the best way to go about reading and writing simple configuration data like we used to use App.config and Web.config <appsettings /> available through ConfigurationManager before, for use within your Windows 8 / Windows RT / Windows Store / Windows Modern UI App?

回答1:

LocalSettings

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.localsettings

OR

RoamingSettings

http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.applicationdata.roamingsettings.aspx

The main difference is that RoamingSettings will be saved to the cloud and thus, can be transferred across different devices for the same user profile. LocalSettings is device-specific.



回答2:

Metro apps don't have exact equivalent of app.config/web.config.

Instead you should use package.appxmanifest to configure windows store specific values.

For local settings you should use ApplicationData api.

If you want to configure application after it is deployed you could simply load remote xml or json file at application start up.



回答3:

In addition to the technical answers above its important to understand why there is no config file for these apps.

WinRT/Windows store apps are client applications so unlike your ASP.NET applications that run on the server and require admin configuration changes, end users are not expected to tinker with these changes (SQL connection, timeouts, appSettings you name it) hence there is no need for such a config file for these apps,

Hope it makes sense



回答4:

You can find a sample to mimic app.config in Windows Store apps based on XML files here

Hth

Stefan