I have a class called Constants.cs that contains app settings. I want to add an App.config file and put the settings from Constants.cs to App.config file in order to be able to run my application in different environments with same settings.
If my constants.cs class looks like this:
public class Constants
{
public static string LoginSubmitText => "Submit";
public static string LoginBackBtnText => "Back";
public static string SettingsPageTitleSize => "25";
}
Should then the App.config file look like this?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key ="LoginSubmitText" value="Submit"/>
<add key ="LoginBackBtnText " value="Back"/>
<add key ="SettingsPageTitleSize" value="25"/>
</appSettings>
</configuration>
And in that case, must I put this App.config file in all three environments, .Android, .IOS and UWP?
Thanks in advance!
You don't have to have App.config in all three platfroms. You can add this class to project with shared code.
I just finished working on similar issue. This is described here in this article. They don't use App.config file and if you insist on having App.config you can write your own implementation of parsing App.config to AppSettings object. I am talking about the method LoadAppSettings. The last part of this method converts json file appsettings.debug.json to AppSettings obejct.
In my case I needed to inject different connection strings regarding to build configuration in my azure pipelines. I use the powershell script to edit appsettings.[build configuration].json file and that solves my issue.