I have a .NET Core worker service app, I have different appsetings.json
files like appsetings.Dev.json
, appsetings.Prod.json
etc. I want to load these appsettings file based on the environment variables provided via either Publish Profiles or command line publishes.
For example, in ASP.NET Core apps, I can add the following tag into .pubxml file
<PropertyGroup>
<EnvironmentName>Dev</EnvironmentName>
</PropertyGroup>
For, ASP.NET Core web apps this will automatically set the environment as Dev and the release build will load the appsetings.Dev.json
file.
For the background app, this approach doesn't work. How can I set environment variables for .net 6 worker apps?
I've also tried to supply environment variables via CLI, but the release build app always uses the environment as "Production" no matter what is provided (Staging, Development, QA etc.)