diff --git a/src/KnifeHub.Web/KnifeHub.Web.csproj b/src/KnifeHub.Web/KnifeHub.Web.csproj
index 5abd14200..b95812e10 100644
--- a/src/KnifeHub.Web/KnifeHub.Web.csproj
+++ b/src/KnifeHub.Web/KnifeHub.Web.csproj
@@ -18,9 +18,9 @@
- 1.6.5
- 1.6.5.0
- 1.6.5.0
+ 1.6.6
+ 1.6.6.0
+ 1.6.6.0
diff --git a/src/KnifeHub.Web/Utils/DotNetUtil.cs b/src/KnifeHub.Web/Utils/DotNetUtil.cs
index ee17ac251..4b8b1bf05 100644
--- a/src/KnifeHub.Web/Utils/DotNetUtil.cs
+++ b/src/KnifeHub.Web/Utils/DotNetUtil.cs
@@ -2,6 +2,8 @@
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
+using System.Reflection;
+
namespace KnifeHub.Web.Utils
{
public class DotNetUtil
@@ -21,9 +23,30 @@ public static string? AspNetCoreFileVersion
{
get
{
+ string? aspNetCoreVersion = null;
var assembly = typeof(Microsoft.AspNetCore.Http.HttpContext).Assembly;
- var fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
- string? aspNetCoreVersion = fileVersionInfo.FileVersion;
+ if (string.IsNullOrEmpty(assembly.Location))
+ {
+ // 当程序集是动态加载的或者是从内存中加载的(比如在ASP.NET Core应用中,某些程序集可能被嵌入到主程序集中,或者通过AssemblyLoadContext动态加载),此时Location属性可能为空。
+ // 使用 AssemblyFileVersionAttribute 获取文件版本
+ try
+ {
+ var fileVersionAttr = assembly.GetCustomAttribute();
+ aspNetCoreVersion = fileVersionAttr?.Version;
+ }
+ catch (Exception ex)
+ { }
+ }
+ else
+ {
+ try
+ {
+ var fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
+ aspNetCoreVersion = fileVersionInfo.FileVersion;
+ }
+ catch (Exception ex)
+ { }
+ }
return aspNetCoreVersion;
}
@@ -33,9 +56,29 @@ public static string? AspNetCoreProductVersion
{
get
{
+ string? aspNetCoreVersion = null;
var assembly = typeof(Microsoft.AspNetCore.Http.HttpContext).Assembly;
- var fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
- string? aspNetCoreVersion = fileVersionInfo.ProductVersion;
+ if (string.IsNullOrEmpty(assembly.Location))
+ {
+ try
+ {
+ var versionAttr1 = assembly.GetCustomAttribute();
+ var versionAttr2 = assembly.GetCustomAttribute();
+ aspNetCoreVersion = versionAttr1?.Version ?? "null" + "+" + versionAttr2?.InformationalVersion ?? "null";
+ }
+ catch (Exception ex)
+ { }
+ }
+ else
+ {
+ try
+ {
+ var fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
+ aspNetCoreVersion = fileVersionInfo.ProductVersion;
+ }
+ catch (Exception ex)
+ { }
+ }
return aspNetCoreVersion;
}
diff --git a/src/KnifeHub.Web/wwwroot/index.html b/src/KnifeHub.Web/wwwroot/index.html
index 72134578d..cbeaf23e7 100644
--- a/src/KnifeHub.Web/wwwroot/index.html
+++ b/src/KnifeHub.Web/wwwroot/index.html
@@ -2,7 +2,7 @@
- KnifeHub-v1.6.5
+ KnifeHub-v1.6.6