0

I deployed an ASP.NET Core 7 application to Linux Web Application in Azure.

When I access the URL I get an Application Error and the Logs shows:

System.IO.FileNotFoundException: 
The configuration file 'settings..json' was not found and is not optional. 

It seems it is missing the Environment value so it should be:

settings.production.json

In the Azure Application Service Configuration I have:

[
  {
    "name": "ASPNETCORE_ENVIRONMENT",
    "value": "production",
    "slotSetting": false
  }
]

And the application Program.cs code is:

Serilog.Log.Logger = new 

Serilog.LoggerConfiguration()
  .WriteTo.Console(LogEventLevel.Verbose)
  .CreateBootstrapLogger();

try {

  Serilog.Log.Information("Starting up");

  WebApplicationBuilder builder = WebApplication.CreateBuilder(new WebApplicationOptions { 
    Args = args, 
    WebRootPath = "webroot" 
  });

  builder.Configuration
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("settings.json", false, true)
    .AddJsonFile($"settings.{Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT")}.json", false, true)
    .AddEnvironmentVariables();

  // Remaining code 

Am I doing something wrong or something change in Net 7?

Miguel Moura
  • 36,732
  • 85
  • 259
  • 481
  • Visit https://stackoverflow.com/questions/73538978/can-i-read-environment-variable-from-azure-app-settings-by-using-environment-get – Ali Yavari Dec 09 '22 at 20:58
  • Why do I need to use Azure App Configuration Store? I had this working fine in previous NET Core applications. And I am using NET Core. – Miguel Moura Dec 09 '22 at 21:04
  • As Specified in this [MS Doc](https://learn.microsoft.com/en-us/azure/app-service/configure-common?tabs=portal#configure-connection-strings), Storing the connection strings in Azure app Service configuration section is used to run the web application in cloud with production settings and storing the `web.config` files used to debug/run locally with the development settings. –  Dec 10 '22 at 01:57
  • Review https://learn.microsoft.com/en-us/aspnet/core/fundamentals/environments?view=aspnetcore-7.0. Note that environment variables are case sensitive in Linux, as opposed to Windows. Should use "Production", though this is the default and doesn't need to be specified. In Azure, configuration should be provided through the configuration of the app service, not a JSON file. – Noah Stahl Dec 10 '22 at 15:33

1 Answers1

0

In short, this problem occurs because the settings.production.json file was not included at the time of release.

We can verify this by uploading the 'settings.production.json' file to the scm site. The URL is https://your_appname_azurewebsites.net/newui .

enter image description here

Solution:

  1. Official doc : Include files
  2. Sample: Use ResolvedFileToPublish in ItemGroup
Jason Pan
  • 15,263
  • 1
  • 14
  • 29