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:
visual studio with F5 - it can't see my system environment variablebin/Debug folder with dotnet 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?
Restart your Visual Studio.
You probably just declared your Environment Variables hence Visual Studio does not see them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With