簡體   English   中英

Azure Web 作業控制台應用程序配置設置未被 Azure 應用服務配置設置覆蓋

[英]Azure Web Job Console application config setting not getting overridden by Azure App Service Config setting

我在 Azure 應用服務中將 Dot Net 6.0 控制台應用程序作為 Web 作業運行。 我想用 Azure 應用服務配置中的配置覆蓋 apsettings.json 文件中的配置設置。

這是控制台應用程序中用於讀取配置的代碼

static async Task Main(string[] args)
        {            
            var configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                .AddJsonFile("appsettings.json").Build();
            var testKey = configuration.GetSection($"TestKey").Value;
            Console.WriteLine($"TestKey {testKey}");

這是 apsettings.json 文件

{ "TestKey": "TestValue" }

Azure App Service 中的應用程序設置,其中控制台應用程序部署為 Web 作業

在此處輸入圖像描述

Web 作業的輸出

在此處輸入圖像描述

據我所知,要覆蓋 apsettings.json 文件中的配置設置,請在 Program.cs 中添加.AddEnvironmentVariables

我已經在我的環境中重現並得到了預期的結果。

程序.cs

var config = new ConfigurationBuilder()
                     .SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
                     .AddJsonFile("appsettings.json")
                     .AddEnvironmentVariables()
                     .Build();
            var testKey = config.GetSection($"TestName").Value;
            Console.WriteLine($"TestKey {testKey}");

應用設置.json

{
 "TestName": "TestValue"
}

Azure App Service(門戶)中的應用程序設置:在此處輸入圖像描述

輸出:

在添加.AddEnvironmentVariables之前:

在此處輸入圖像描述

添加.AddEnvironmentVariables后:

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM