Reputation: 1994
Normally I ship my applications with a predefined configuration which is located in the app.config. So I can publish for customer A other predefined settings then for customer B
How can I achieve this in uwp?
Upvotes: 3
Views: 1044
Reputation: 2148
Use this settings class https://github.com/joseangelmt/ObservableSettings. With it you don't need to create a xml file and you can set predefined values via attribute decoration of your properties, and also it's observable.
Upvotes: 1
Reputation: 6046
As UWP apps are intended to be deployed via the Store, there's no need for an app.config
file any longer. If you still want to produce a similar behavior, you'll have to work using compiler directives.
The easiest way would be to create a file similiar to the well-known app.config
:
<Config>
<!-- key-value pairs go here -->
</Config>
Create a config file for every customer you have...
Assets
CustomerA.config
CustomerB.config
CustomerC.config
...and load it via a compiler directive:
public Config GetConfig()
{
var configFileName = GetConfigName();
// Load config...
}
private string GetConfigName()
{
#if CUSTA
return "CustomerA.config";
#endif
#if CUSTB
return "CustomerB.config";
#endif
#if CUSTC
return "CustomerC.config";
#endif
throw new NotSupportedException(
"Assembly was compiled for a customer which config doesn't exist.");
}
Note: If the amount of different config files might increase to an unknown number, you'd rather implement a web service identifying the customer and providing the config.
EDIT: Using a single configuration file in your app would also be possible (that would prevent the compiler directives), and therefore modify the XML via XSLT in different build configurations.
The principle stays the same, but you got the annoying part out of your code into XSLT.
Upvotes: 1