Our developers are writing some Windows Services in .NET Core 3.1.
As I understand it, the typical pattern for Core development is to check the DOTNET_ENVIRONMENT variable to switch on different configurations.
For ReasonsTM, we want to avoid setting system-level or even user-level machine environment variables. Some of the reasons are:
- something else to set up when rolling out a new server
- might want to run different "environments" on the same server -- not for services, maybe, but for other commandline apps
For Kestrel hosted apps launched by IIS, extra environment values can be set in web.config. This can't apply to commandline apps.
What's the best practice for this? Is there a way to set environment variables before launching the executable? Or set environment variables within the process, at startup time, by reading them from a config file?
Other things to mention:
- When we start containerizing things, setting container-level environment variables is obviously the way to go, but for shared Windows servers (actually VMs) like this, we need a different approach.
- We have reviewed https://docs.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-3.1 . Even though it is targeted at ASP.NET Core and not console/service apps in Core.