I have a problem with reading environment variables. I have 2 projects under same solution. Basic i need to be able to read my environment Variables when i come from my webjob.
The two project are a asp.net-core-mvc project and a .net core console project.
My console project is a "Webjob" with a reference to my web app project.
When my "Webjob" is running, it hits a method in my web app. Then i tries to get the environment variables from my web app. Which returns null, becouse it is not set.
Is there any way to run it so i can get the environment varaible from my web app when i come from my webjob?
the code i run to get the variables when my web app is running alone is
var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
You cannot, nor should you, reference an ASP.NET Core project from another project and directly hit actions as if they were methods. You need to start the ASP.NET Core project and have it running, and then make requests to it from your console app using
HttpClient
. Otherwise, none of the stuff inStartup
happens (because it's not running), and as a result, you have no access to services such as configuration.