There are 3 ways that I have found to be working within Startup.cs
- use Environment variables. This however, only works if you also have added the environmentvariables. (builder.AddEnvironmentVariables(); )
- Resolve IHostingEnvironment from Services.
var sv = (IHostingEnvironment)services.FirstOrDefault(f => f.ServiceType == typeof(IHostingEnvironment)).ImplementationInstance;
var path = sv.ContentRootPath;
Though, I can imagine you would rather resolve HostingEnvironment but this does not work during ConfigureServices scope..
- Use Directory
eg: var path = Directory.GetCurrentDirectory();
var env = Configuration.GetSection("ASPNETCORE_CONTENTROOT");
var path = env.Value