【问题标题】:Is there a web.config equivalent for UWP App development?是否有适用于 UWP 应用开发的 web.config?
【发布时间】:2019-10-11 06:06:25
【问题描述】:

在 Web 开发中,我们有 web.config,我可以在其中分别为每个客户端手动配置一些应用程序设置。 UWP 应用程序是否有类似的东西[我正在开发 Windows UWP 应用程序。]

【问题讨论】:

  • 在客户端设备上安装应用程序后,我在哪里可以找到外部文件(例如:settings.xml)......有什么想法吗?
  • 在 uwp for windows 应用程序中有 App.xaml 文件,您可以在其中配置应用程序设置。即使在 app.xaml 文件中,您也可以捕获应用程序启动恢复理想关闭事件.

标签: uwp uwp-xaml windows-community-toolkit


【解决方案1】:

希望对你有帮助。

您可以添加appsettings.json文件 例如:-

appsettings.json

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

确保 appsettings.json 文件属性将“复制到输出目录”设置为“始终复制”。

像这样从appsettings.json 文件中查找值-

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;

谢谢!!!

【讨论】:

    猜你喜欢
    • 2020-08-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-17
    • 1970-01-01
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多