Skip to content

Commit 88a83d6

Browse files
Show full informational version for feature management library (#558)
* get full informational version name * use getcustomattribute * comment revision
1 parent 1a66edb commit 88a83d6

File tree

1 file changed

+23
-2
lines changed
  • src/Microsoft.Extensions.Configuration.AzureAppConfiguration

1 file changed

+23
-2
lines changed

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/TracingUtils.cs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.Collections.Generic;
66
using System.Diagnostics;
77
using System.Linq;
8+
using System.Reflection;
89
using System.Security;
910
using System.Text;
1011
using System.Threading.Tasks;
@@ -79,8 +80,28 @@ public static string GetAssemblyVersion(string assemblyName)
7980
{
8081
if (!string.IsNullOrEmpty(assemblyName))
8182
{
82-
// Return the version using only the first 3 fields and remove additional characters
83-
return AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly => assembly.GetName().Name == assemblyName)?.GetName().Version?.ToString(3).Trim('{', '}');
83+
Assembly infoVersionAttribute = AppDomain.CurrentDomain.GetAssemblies().SingleOrDefault(assembly => assembly.GetName().Name == assemblyName);
84+
85+
if (infoVersionAttribute != null)
86+
{
87+
string informationalVersion = infoVersionAttribute.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
88+
89+
if (string.IsNullOrEmpty(informationalVersion))
90+
{
91+
return null;
92+
}
93+
94+
// Commit information is appended to the informational version starting with a '+', so we remove
95+
// the commit information to get just the full name of the version.
96+
int plusIndex = informationalVersion.IndexOf('+');
97+
98+
if (plusIndex != -1)
99+
{
100+
informationalVersion = informationalVersion.Substring(0, plusIndex);
101+
}
102+
103+
return informationalVersion;
104+
}
84105
}
85106

86107
return null;

0 commit comments

Comments
 (0)