1

We have multiple environments running from the same machine. For our web applications we can easily set the ASPNETCORE_ENVIRONMENT variable for each different web application using the web.config.

However, we also are deploying console applications that are scheduled to run using Windows Task Scheduler. We haven't been able to figure out how to set per console app a different ASPNETCORE_ENVIRONMENT variable.

We've looked at the Microsoft documentation and it shows using a command line that looks like this:

set ASPNETCORE_ENVIRONMENT=Development

Does that set the whole machine to that environment? We don't understand the scope of running a command like that.

Anyone have any insight to the intended use for setting this variable for a console app?

Community
  • 1
  • 1
Ristogod
  • 905
  • 4
  • 14
  • 29
  • you may try `--environment argument` with `dotnet run`. See [run .net core application in development from the command line](https://stackoverflow.com/questions/43412065/run-net-core-application-in-development-from-the-command-line/43412502#43412502) – Set Sep 18 '17 at 20:22

1 Answers1

3

ASPNETCORE_ENVIRONMENT is a machine environment variable, yes it sets the whole machine to that environment.

You have an architectural issue going on here, ASPNETCORE_ENVIRONMENT is not your problem.

Why would a machine be in multiple environments, how is that even possible if you think about it? You just do not have enough "machines".

You should be using Virtual Machines or Docker containers, I recommend Docker containers. Or just use more machines.

Just because you have the luxury of using different environments in IIS isolated web applications does not mean that a machine has the luxury of being in more than one environment. That is why Virtual machines and Docker containers exist, to break apart a machine into different environments and applications.

Brian Ogden
  • 18,439
  • 10
  • 97
  • 176
  • That makes sense and I don't disagree. Unfortunately it is completely out of my control how our applications are hosted. Docker is forbidden, a directive of the all-mighty hosting department and their infinite wisdom. It comes down to the business not supporting the needs of our applications due to budgeting and politics. – Ristogod Sep 20 '17 at 13:12
  • @Ristogod that sounds like a strange and misguided all-mighty, an uninformed hosting department...virtual machines are another option, or more machines – Brian Ogden Sep 20 '17 at 16:46
  • @Ristogod I do not think this answers your question. An architecture is informed somewhat by your infrastructure limitations. I face the same issue. We've been given one machine and have to make do with that. I solved the problem by passing in arguments to the console application. I effectively simulated the environment variable in that way. It is not as desirable as having one environment to a machine. If you are fortunate enough to be replete with VMs in your infrastructure, (or Docker etc), then you are good to go with the 1 Environment per machine architecture. Otherwise, do what you can. – onefootswill Aug 07 '19 at 00:03