1

I use an Elastic Beanstalk Environment with multiple .NET Core 5.0 projects.

The Apps are running fine with my Procfile

api-user: dotnet ./api-user/api-user.dll --urls http://localhost:5000
api-shop: dotnet ./api-shop/shop.dll --urls http://localhost:5001

Unfortunately .NET seems to be unable to pick up the Configuration from my appsettings.json and appsettings.<ENVIRONMENT>.json files.

I logged all registered ConfigurationProviders in .NET and they are present as JsonConfigurationProvider

Also the files are present in the working directory. I checked that via SSH with:

cd var/app/current/api-user
cat appsettings.json

Configuration with appsettings.json works fine locally in Development and Production. Why is this not the case for the cloud environment?

After_8
  • 189
  • 1
  • 4
  • 16

2 Answers2

1

Finally I was able to figure it out. The reason for the missing appsettings.json is the BasePath of the Application

Before running dotnet command i need to cd into the working directory:

api-user: cd api-user && dotnet api-user.dll --urls http://localhost:5000
api-shop: cd api-shop && dotnet shop.dll --urls http://localhost:5001
After_8
  • 189
  • 1
  • 4
  • 16
  • Lucky you were here. I may be the only other person so far who had the exact same issue. It gets lonely on SO the deeper you get into AWS for different frameworks. Thank you! – BeniaminoBaggins Jul 31 '23 at 03:41
0

When you run locally, VS reads launchSettings.json file, where ASPNETCORE_ENVIRONMENT variable is set to the right value (dev, production).

When you run in the cloud, environment variable is not present. I cannot tell you for Amazon, but when you run in Azure, you have to set ASPNETCORE_ENVIRONMENT in the properties of the deployed application in the Cloud (i.e. this is not part of your VS solution, but of the deployed application). I guess Amazon would have something similar and a place to set this variable.

If you run .net app from a shell (I just really don't know how beanstalk works) you should set the env variable, e.g.

setx ASPNETCORE_ENVIRONMENT "Development"

or however your shell does it.

Maxim Zabolotskikh
  • 3,091
  • 20
  • 21
  • `ASPNETCORE_ENVIRONMENT` is set in App configuration. I already checked this. Also `appsettings.json` should still work – After_8 Sep 29 '21 at 12:28