简体   繁体   中英

.NET Core 3.1 app not reading Azure Pipelines variable

I've got a .NET Core 3.1 test project, with the following code:

var configuration = new ConfigurationBuilder()
    .SetBasePath(Environment.CurrentDirectory)
    .AddJsonFile("appsettings.json", optional: false, reloadOnChange: false)
    .AddEnvironmentVariables()
    .Build();

I then try and access config value, in one of my tests:

var storageAcc = configuration["AzureWebJobsStorage"];

Works fine on local, as it's using appsettings.json , which has the following:

{
  "AzureWebJobsStorage": "UseDevelopmentStorage=true"
}

I'm now trying to override this in Azure Pipelines, via a variable: 在此处输入图像描述

But when i run the build on CI, my code crashes, saying the value is null .

What's strange is this exact setup/code was working fine on .NET Core 2.2, but errored when i upgraded to .NET Core 3.1. So wondering if it's an issue with Microsoft.Extensions.Configuration 3.x upgrade path? (can't find anything online)

Anyone have any ideas?

Thanks in advance!

Okay, found the answer.

TLDR; case-sensitivity fail

I had to change the key in the appsettings.json to AZUREWEBJOBSSTORAGE . I figured this out because when dumping the env vars on Azure Pipelins, i saw the variable was uppercase (note: i am using the ubuntu hosted agent, which could play a factor here). So, i guess this wasn't overriding properly if the case was different.

Now, i have no idea how this worked on .NET Core 2.2, but doesn't on .NET Core 3.1 (i didn't touch Azure Pipelines, just the SDK for the project). If anyone happens to figure that out, please let me know!

Hope that helps someone. Was pure luck that i figured this out:(

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM