ASP.NET Core 3.0 get_HostingEnvironment() Method not found in extension
For the netstandard2.0
project, I could only get the HostingEnvironment
in the HostBuilderContext
(from IHostBuilder.ConfigureAppConfiguration
) - with the Microsoft.Extensions.Hosting.Abstractions
package installed:
public static IHostBuilder CustomConfigureAppConfiguration(this IHostBuilder hostBuilder)
{
hostBuilder.ConfigureAppConfiguration((context, config) =>
{
// this works with Microsoft.Extensions.Hosting.Abstractions installed
var env = context.HostingEnvironment;
});
return hostBuilder;
}
HostingEnvironment
from WebHostBuilderContext
(from IWebHostBuilder.ConfigureAppConfiguration) still throws an exception when executed by a netcoreapp3.0
project. This worked fine with previous versions.
Also I can still inspect it during debug when commented out:
Something still seems a bit off, but at least this works now.
UPDATE
After more digging I found the difference in references:
- netcoreapp3.0
- via shared framework Microsoft.AspNetCore.Hosting.Abstractions, Version=3.0.0.0
- netstandard2.0
via NuGet Microsoft.AspNetCore.Hosting.Abstractions, Version=2.2.0.0
v2.2 exposes Microsoft.AspNetCore.Hosting.IHostingEnvironment
which has been deprecated in v3.0
As of 2019/10/01 v3.0 is not available on NuGet.