in src/Elastic.Transport/Requests/MetaData/RuntimeVersionInfo.cs [88:131]
private static string GetNetCoreVersion()
{
// for .NET 5+ we can use Environment.Version
if (Environment.Version.Major >= 5)
{
const string dotNet = ".NET ";
var index = RuntimeInformation.FrameworkDescription.IndexOf(dotNet, StringComparison.OrdinalIgnoreCase);
if (index >= 0)
{
return RuntimeInformation.FrameworkDescription.Substring(dotNet.Length);
}
}
// next, try using file version info
var systemPrivateCoreLib = FileVersionInfo.GetVersionInfo(typeof(object).Assembly.Location);
if (TryGetVersionFromProductInfo(systemPrivateCoreLib.ProductVersion, systemPrivateCoreLib.ProductName, out var runtimeVersion))
{
return runtimeVersion;
}
var assembly = typeof(System.Runtime.GCSettings).GetTypeInfo().Assembly;
if (TryGetVersionFromAssemblyPath(assembly, out runtimeVersion))
{
return runtimeVersion;
}
//At this point, we can't identify whether this is a prerelease, but a version is better than nothing!
var frameworkName = Assembly.GetEntryAssembly()?.GetCustomAttribute<TargetFrameworkAttribute>()?.FrameworkName;
if (TryGetVersionFromFrameworkName(frameworkName, out runtimeVersion))
{
return runtimeVersion;
}
if (IsRunningInContainer)
{
var dotNetVersion = Environment.GetEnvironmentVariable("DOTNET_VERSION");
var aspNetCoreVersion = Environment.GetEnvironmentVariable("ASPNETCORE_VERSION");
return dotNetVersion ?? aspNetCoreVersion;
}
return null;
}