I have an asp.net core application (.NET Core 2.1). There is a code in ConfigureServices method in Startup class:
Configuration = new ConfigurationBuilder()
.SetBasePath(_hostingEnvironment.ContentRootPath)
.AddJsonFile("appsettings.json", false, true)
.AddJsonFile($"appsettings.{_hostingEnvironment.EnvironmentName}.json", false, true)
.AddEnvironmentVariables("MyApp:")
.Build();
Also I set system environment variable MyApp:DumpFolder to override DumpFolder setting in appsettings.json. And here I faced with strange behavior:
- If I run the application from
visual studiowith F5 - it can't see my system environment variable - If I build and run it from
bin/Debugfolder withdotnet MyApp.dll- it loads variables properly.
I inspected asp.net core and see it uses Environment.GetEnvironmentVariables() method which by default (without specified EnvironmentVariableTarget) retreives variables from current process. I don't understand why variables aren't loaded when I run the application from visual studio?