ApplicationVersion is overwritten by DOTNET_VERSION of aspnet container images
- List of NuGet packages and version that you are using: 2.22.0
- Runtime version: net8.0
- Hosting environment: AKS Windows K8s container
Describe the bug
The ApplicationVersion reported to Application Insights is overwritten by the environment variable DOTNET_VERSION which is set in all aspnet Docker containers by Microsoft.
Using the, e.g., /dotnet/aspnet/8.0-nanoserver-1809 image, sets the environment variable DOTNET_VERSION. The ASP.NET Core application's WebHostBuilder by default adds an environment variable configuration provider that strips the "DOTNET_" prefix resulting in a configuration value for "VERSION". The extension method to add Application Insights (in the end calling the internal method Microsoft.Extensions.DependencyInjection.ApplicationInisghtsExtensions.AddTelemetryConfiguration) in turn checks whether there is a configuration value "version" and if so sets the ApplicationVersion property to this version number.
This results in the ASP.NET Core SDK version number being reported as the ApplicationVersion.
Actually this should affect lots of people, it is a mystery to me why this has not been reported yet.
Best regards, D.R.
I was not able to reproduce this scenario. You're right that when we run it, it sets the DOTNET_VERSION as the runtime version. In my case, for example, using the image mcr.microsoft.com/dotnet/aspnet:8.0, the environment variables were:
HOSTNAME=3229479f75e9
ASPNETCORE_ENVIRONMENT=Development
DOTNET_VERSION=8.0.11
APP_UID=1654
PWD=/app
HOME=/root
ASPNETCORE_LOGGING__CONSOLE__DISABLECOLORS=true
ASPNETCORE_HTTP_PORTS=8080
TERM=xterm
SHLVL=1
ASPNET_VERSION=8.0.11
DOTNET_RUNNING_IN_CONTAINER=true
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
_=/usr/bin/printenv
However, it didn't affect the application version initializer as you said. Even with those environment variables, the field ApplicationVersion sent to Application Insights was correct as follows:
PS: Tested on .NET 9.0 and .NET 8.0
Is this something which affects only Windows containers maybe? Would be a surprise to be sure, but it's a difference between our test setups.