Skip to content

Commit a349419

Browse files
committed
Fix ASP.NET Core version detection
1 parent 11ea502 commit a349419

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

samples/TagHelperPack.Sample/Services/AspNetCoreVersion.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,17 @@ private string GetAspNetCoreVersion()
107107
var aspNetCoreAssembly = AppDomain.CurrentDomain.GetAssemblies()
108108
.FirstOrDefault(a => string.Equals(a.GetName().Name, "Microsoft.AspNetCore", StringComparison.OrdinalIgnoreCase));
109109

110+
// Get AssemblyInformationalVersion
111+
var assemblyInformationalVersion = aspNetCoreAssembly.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion;
112+
if (assemblyInformationalVersion != null)
113+
{
114+
var indexOfPlus = assemblyInformationalVersion.IndexOf('+');
115+
return indexOfPlus >= 0
116+
? assemblyInformationalVersion.Substring(0, indexOfPlus)
117+
: assemblyInformationalVersion;
118+
}
119+
120+
// Try shared framework directory name
110121
try
111122
{
112123
var aspNetCorePath = aspNetCoreAssembly.Location;
@@ -116,7 +127,7 @@ private string GetAspNetCoreVersion()
116127
}
117128
}
118129
catch (Exception) { }
119-
130+
120131
// Just use the version of the Microsoft.AspNetCore assembly
121132
return aspNetCoreAssembly.GetName().Version.ToString();
122133
}

0 commit comments

Comments
 (0)