.NetCore中的Appsettings转换无法正常工作

时间:2019-06-18 19:07:49

标签: c# json asp.net-core appsettings

我已经开发了一个Web API,并将其发布在azurewebsites.net上。 我添加了以下其他appsettings:-

  1. appsettings.Dev.json
  2. appsettings.Test.json
  3. appsettings.Prod.json

为了能够从这些appsettings转换中提取值,我进行了以下代码更改:

尝试了此处提到的解决方案: https://stackoverflow.com/a/44953524/10485667

甚至尝试仅使用开发/调试,登台和生产/发布,而不接受开发,测试和生产。但是没有运气。只会从主appsettings.json中发布值。

Startup.cs

(lldb) mem read -fA `$rsp - 16 * 8` `$rsp` -fA 
0x7ffeefbff660: 0x0000000000000000
0x7ffeefbff668: 0x00007ffeefbff660
0x7ffeefbff670: 0x0000003002000000
0x7ffeefbff678: 0x00007fff6e2ee568 libsystem_platform.dylib`__platform_sigaction + 103
0x7ffeefbff680: 0x0000000000000000
0x7ffeefbff688: 0x0000000000000000
0x7ffeefbff690: 0x0000000000013dc9
0x7ffeefbff698: 0x0000000000000000
0x7ffeefbff6a0: 0x00007fff6e238fe2 libsystem_kernel.dylib`__sigaction + 10
0x7ffeefbff6a8: 0x0000000000000000
0x7ffeefbff6b0: 0x000000000000001e
0x7ffeefbff6b8: 0x0000000000013dc9
0x7ffeefbff6c0: 0x00007ffeefbff700
0x7ffeefbff6c8: 0x0000000100002020 _dyld_private
0x7ffeefbff6d0: 0x000000000000000e
0x7ffeefbff6d8: 0x0000000100000f45 signals`main + 53 at signals.c:13:3

甚至尝试过以下代码:

public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .SetBasePath(env.ContentRootPath)
            .AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
#if DEBUG
                    .AddJsonFile($"appsettings.Dev.json", optional: true)
#endif
                    .AddEnvironmentVariables();

        Configuration = builder.Build();
        appSettings = Configuration.Get<AppSettingsModel>().AppSettings;

    }

试图更改Program.cs:

AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)

尝试了Internet上提供的所有可能解决方案,但没有运气。发布到天蓝色后,它仅从appsettings.json

中获取值

我认为尝试这些解决方案时可能会犯一些概念上的错误。任何帮助都将受到赞赏。

预先感谢

0 个答案:

没有答案