diff --git a/utils/build/docker/dotnet/GetAssemblyVersion/Program.cs b/utils/build/docker/dotnet/GetAssemblyVersion/Program.cs index fb1dce4a4fb..d268bb74f28 100644 --- a/utils/build/docker/dotnet/GetAssemblyVersion/Program.cs +++ b/utils/build/docker/dotnet/GetAssemblyVersion/Program.cs @@ -1,10 +1,24 @@ -if (args.Length == 0 || string.IsNullOrWhiteSpace(args[0])) +using System.Reflection; + +if (args.Length == 0 || string.IsNullOrWhiteSpace(args[0])) { Console.WriteLine("Usage: GetAssemblyVersion "); return; } var fullPath = Path.GetFullPath(args[0]); -var assembly = System.Reflection.Assembly.LoadFile(fullPath); -var version = assembly.GetName().Version?.ToString(3); +var assembly = Assembly.LoadFile(fullPath); + +// Prefer the informational version (e.g. 3.58.0-prerelease+), because the assembly +// version is the same for a prerelease and its release (3.58.0.0). Drop the "+..." build metadata +// so it matches the version the tracer reports. +var informationalVersion = assembly + .GetCustomAttribute()? + .InformationalVersion + .Split('+')[0]; + +var version = string.IsNullOrWhiteSpace(informationalVersion) + ? assembly.GetName().Version?.ToString(3) + : informationalVersion; + Console.Write(version);