Search code examples
uwpuwp-xamlwindows-community-toolkit

Is there a web.config equivalent for UWP App development?


In web development we have web.config where I can manually configure a few app settings for each client separately. Is there a similar thing for UWP apps [I am developing a Windows UWP app.]


Solution

  • Hope, it helps you.

    You can add appsettings.json file e.g.:-

    appsettings.json

    {
      "key1": "value1",
      "key2": "value2"
    }
    

    Make sure that appsettings.json file property set "Copy To Output Directory" to "Copy always".

    Find Values from appsettings.json file like this-

    var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
    IConfiguration configuration = builder.Build();
    string GetValue1 = configuration.GetSection("key1").Value;
    string GetValue2 = configuration.GetSection("key2").Value;
    

    Thanks!!!