ApplicationInsights-dotnet
ApplicationInsights-dotnet copied to clipboard
AspNetCore project & FrameworkReferences & IHostingEnvironment
These are some issues we want to follow up on that were discovered as part of deprecating Net Core 2.1 #2251.
https://github.com/microsoft/ApplicationInsights-dotnet/blob/develop/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Microsoft.ApplicationInsights.AspNetCore.csproj
- FrameworkReference
- IHostingEnvironment
At the moment, this project is built on netstandard2.0 which does not support FrameworkReferences or the new IHostEnvironment interface.
To use these new features, this project needs to be upgraded to either NetCoreApp3.1, Net5.0, or Net6.0.
We haven't decided when this upgrade will take place.
FrameworkReferences
Individual package references should be replaced with framework references wherever possible. (https://docs.microsoft.com/en-us/aspnet/core/fundamentals/target-aspnetcore?view=aspnetcore-5.0&tabs=visual-studio)
AspNetCore project has a few explicit dependencies to resolve some security vulnerabilities. This can be replaced by switching to FrameworkReferences:
<ItemGroup Condition="'$(IsNetCore)' == 'True'">
<FrameworkReference Include="Microsoft.AspNetCore.App"/>
</ItemGroup>
IHostingEnvironment has been deprecated.
- This issue was first reported in #1869.
- See my abandoned PR for attempts to remove this dependency: #2412.
The IHostingEnvironment was marked obsolete and replaced with IHostEnvironment.
See also: https://weblog.west-wind.com/posts/2020/Feb/26/Working-with-IWebHostEnvironment-and-IHostingEnvironment-in-dual-targeted-NET-Core-Projects
IHostingEnvironment' is obsolete: 'This type is obsolete and will be removed in a future version. The recommended alternative is Microsoft.AspNetCore.Hosting.IWebHostEnvironment.
We have two dependencies on this interface:
-
DefaultApplicationInsightsServiceConfigureOptions This is used to find the
appsettings.jsonfile. https://github.com/microsoft/ApplicationInsights-dotnet/blob/786175c6059e77f16f1de9cff1d8a9d7511cad05/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/Extensions/DefaultApplicationInsightsServiceConfigureOptions.cs#L25 -
AspNetCoreEnvironmentTelemetryInitializer This is used to read the EnvironmentName and set custom properties on individual telemetry items. https://github.com/microsoft/ApplicationInsights-dotnet/blob/786175c6059e77f16f1de9cff1d8a9d7511cad05/NETCORE/src/Microsoft.ApplicationInsights.AspNetCore/TelemetryInitializers/AspNetCoreEnvironmentTelemetryInitializer.cs#L21
Trying to remove this broke dozens of our tests. Need to take more time to explore if we can remove these dependencies or provide some other workaround.
Hi,
please, prioritize it 📈
Thank you
Hi,
any progress on this issue?
Thanks
Can we get any update on this ? Seems like this should be a pressing matter since the codebase is using an obsolete IHostingEnvironment still
Hi, no update. When I looked into this it was deemed to be a significant effort and currently out of scope.
If someone in the community has time to dig into IHostingEnvironment/IHostEnvironment I can make time to review any PRs. I don't remember which tests were failing, but if someone forks this repo they'll get all our CI as well.
This issue is stale because it has been open 300 days with no activity. Remove stale label or this will be closed in 7 days. Commenting will instruct the bot to automatically remove the label.