From 9282b910ba833670a0eb242b1434f202ed7906a5 Mon Sep 17 00:00:00 2001 From: zpc Date: Wed, 10 Jul 2024 19:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E7=89=88=E6=9C=AC=E4=BF=A1?= =?UTF-8?q?=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HuanMengProject.sln | 13 +++-- .../HuanMeng.MiaoYu.Code.csproj | 1 + .../AssemblyHelper/AssemblyInfo.cs | 53 +++++++++++++++++++ .../AssemblyHelper/AssemblyInfoHelper.cs | 39 ++++++++++++++ src/0-core/HuanMeng.Utility/Class1.cs | 9 ++++ .../HuanMeng.Utility/HuanMeng.Utility.csproj | 8 +++ .../HuanMeng.MiaoYu.WebApi.csproj | 1 + src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs | 12 +++-- 8 files changed, 128 insertions(+), 8 deletions(-) create mode 100644 src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfo.cs create mode 100644 src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfoHelper.cs create mode 100644 src/0-core/HuanMeng.Utility/Class1.cs create mode 100644 src/0-core/HuanMeng.Utility/HuanMeng.Utility.csproj diff --git a/HuanMengProject.sln b/HuanMengProject.sln index 426fa18..2a5c74e 100644 --- a/HuanMengProject.sln +++ b/HuanMengProject.sln @@ -33,16 +33,18 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TextGenerationApi", "src\2- EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMnegopneaiTest", "src\5-console\HuanMnegopneaiTest\HuanMnegopneaiTest.csproj", "{D2A74CFA-8A03-4272-89C7-C01830D183F1}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HuanMeng.MiaoYu.Model", "src\0-core\HuanMeng.MiaoYu.Model\HuanMeng.MiaoYu.Model.csproj", "{B845C884-AD1A-4483-A2F6-B218DB14EA2D}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.MiaoYu.Model", "src\0-core\HuanMeng.MiaoYu.Model\HuanMeng.MiaoYu.Model.csproj", "{B845C884-AD1A-4483-A2F6-B218DB14EA2D}" EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{6C59E75C-386D-4325-9752-D7DB8B158BF8}" ProjectSection(SolutionItems) = preProject .editorconfig = .editorconfig EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HuanMeng.MiaoYu.Code", "src\0-core\HuanMeng.MiaoYu.Code\HuanMeng.MiaoYu.Code.csproj", "{6E79742F-1E56-4B7D-94E8-B509D43561FA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.MiaoYu.Code", "src\0-core\HuanMeng.MiaoYu.Code\HuanMeng.MiaoYu.Code.csproj", "{6E79742F-1E56-4B7D-94E8-B509D43561FA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HuanMeng.MiaoYu.WebApi", "src\2-api\HuanMeng.MiaoYu.WebApi\HuanMeng.MiaoYu.WebApi.csproj", "{729950F2-71EE-42C0-8B46-295740DE20BA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "HuanMeng.MiaoYu.WebApi", "src\2-api\HuanMeng.MiaoYu.WebApi\HuanMeng.MiaoYu.WebApi.csproj", "{729950F2-71EE-42C0-8B46-295740DE20BA}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "HuanMeng.Utility", "src\0-core\HuanMeng.Utility\HuanMeng.Utility.csproj", "{48E1532F-8B50-477C-BB78-8AEA89A167CE}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -90,6 +92,10 @@ Global {729950F2-71EE-42C0-8B46-295740DE20BA}.Debug|Any CPU.Build.0 = Debug|Any CPU {729950F2-71EE-42C0-8B46-295740DE20BA}.Release|Any CPU.ActiveCfg = Release|Any CPU {729950F2-71EE-42C0-8B46-295740DE20BA}.Release|Any CPU.Build.0 = Release|Any CPU + {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Debug|Any CPU.Build.0 = Debug|Any CPU + {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Release|Any CPU.ActiveCfg = Release|Any CPU + {48E1532F-8B50-477C-BB78-8AEA89A167CE}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -112,6 +118,7 @@ Global {B845C884-AD1A-4483-A2F6-B218DB14EA2D} = {DD14191F-22CE-48D8-A944-B8A41C97ACD4} {6E79742F-1E56-4B7D-94E8-B509D43561FA} = {DD14191F-22CE-48D8-A944-B8A41C97ACD4} {729950F2-71EE-42C0-8B46-295740DE20BA} = {0C0B6EB5-E41D-46D9-9F60-90D320A2EEF3} + {48E1532F-8B50-477C-BB78-8AEA89A167CE} = {DD14191F-22CE-48D8-A944-B8A41C97ACD4} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {4A1DC406-AFAA-4884-859C-51B9B26E37FC} diff --git a/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj b/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj index fe26c1c..ceb3b43 100644 --- a/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj +++ b/src/0-core/HuanMeng.MiaoYu.Code/HuanMeng.MiaoYu.Code.csproj @@ -31,6 +31,7 @@ + diff --git a/src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfo.cs b/src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfo.cs new file mode 100644 index 0000000..7fbf486 --- /dev/null +++ b/src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfo.cs @@ -0,0 +1,53 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace HuanMeng.Utility.AssemblyHelper +{ + /// + /// 保存各种程序集信息属性的类。 + /// + public class AssemblyInfo + { + /// + /// 获取或设置程序集的版本。 + /// + public string Version { get; set; } + + /// + /// 获取或设置程序集的文件版本。 + /// + public string FileVersion { get; set; } + + /// + /// 获取或设置程序集版本。 + /// + public string AssemblyVersion { get; set; } + + /// + /// 获取或设置程序集的信息性版本。 + /// + public string InformationalVersion { get; set; } + + ///// + ///// 获取或设置与程序集关联的公司名称。 + ///// + //public string Company { get; set; } + + ///// + ///// 获取或设置与程序集关联的产品名称。 + ///// + //public string Product { get; set; } + + /// + /// 获取或设置与程序集关联的版权信息。 + /// + public string Copyright { get; set; } + + /// + /// 获取或设置程序集的描述信息。 + /// + public string Description { get; set; } + } + +} diff --git a/src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfoHelper.cs b/src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfoHelper.cs new file mode 100644 index 0000000..88f72c6 --- /dev/null +++ b/src/0-core/HuanMeng.Utility/AssemblyHelper/AssemblyInfoHelper.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text; + +namespace HuanMeng.Utility.AssemblyHelper +{ + /// + /// 用于检索程序集信息的辅助类。 + /// + public static class AssemblyInfoHelper + { + /// + /// 从正在执行的程序集检索各种属性,并返回一个 AssemblyInfo 对象。 + /// + /// 包含程序集属性的 AssemblyInfo 对象。 + public static AssemblyInfo GetAssemblyInfo() + { + // 获取正在执行的程序集 + Assembly assembly = Assembly.GetExecutingAssembly(); + + // 创建并填充 AssemblyInfo 对象的相关属性 + var assemblyInfo = new AssemblyInfo + { + Version = assembly.GetCustomAttributes().FirstOrDefault()?.Version ?? "", + FileVersion = assembly.GetCustomAttributes().FirstOrDefault()?.Version ?? "", + AssemblyVersion = assembly.GetName().Version.ToString(), + InformationalVersion = assembly.GetCustomAttributes().FirstOrDefault()?.InformationalVersion ?? "", + //Company = assembly.GetCustomAttributes().FirstOrDefault()?.Company ?? "", + //Product = assembly.GetCustomAttributes().FirstOrDefault()?.Product ?? "", + Copyright = assembly.GetCustomAttributes().FirstOrDefault()?.Copyright ?? "", + Description = assembly.GetCustomAttributes().FirstOrDefault()?.Description ?? "" + }; + + return assemblyInfo; + } + } +} diff --git a/src/0-core/HuanMeng.Utility/Class1.cs b/src/0-core/HuanMeng.Utility/Class1.cs new file mode 100644 index 0000000..1b9f903 --- /dev/null +++ b/src/0-core/HuanMeng.Utility/Class1.cs @@ -0,0 +1,9 @@ +using System; + +namespace HuanMeng.Utility +{ + public class Class1 + { + + } +} diff --git a/src/0-core/HuanMeng.Utility/HuanMeng.Utility.csproj b/src/0-core/HuanMeng.Utility/HuanMeng.Utility.csproj new file mode 100644 index 0000000..b4b43f4 --- /dev/null +++ b/src/0-core/HuanMeng.Utility/HuanMeng.Utility.csproj @@ -0,0 +1,8 @@ + + + + netstandard2.1 + enable + + + diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj index c374a35..f0b9df2 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/HuanMeng.MiaoYu.WebApi.csproj @@ -18,6 +18,7 @@ + diff --git a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs index 1fd0f8c..3e94cac 100644 --- a/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs +++ b/src/2-api/HuanMeng.MiaoYu.WebApi/Program.cs @@ -8,8 +8,10 @@ using HuanMeng.MiaoYu.Code.TencentUtile; using HuanMeng.MiaoYu.Code.Users.UserAccount.VerificationCodeManager; using HuanMeng.MiaoYu.Code.JwtUtil; using Microsoft.AspNetCore.Authentication.JwtBearer; +using HuanMeng.Utility.AssemblyHelper; var builder = WebApplication.CreateBuilder(args); - +// 检索程序集信息 +AssemblyInfo assemblyInfo = AssemblyInfoHelper.GetAssemblyInfo(); // Add services to the container. builder.Services.AddHttpContextAccessor(); //添加httpContext注入访问 #region 添加跨域 @@ -57,7 +59,7 @@ builder.Services.AddSwaggerGen(c => {securityScheme, Array.Empty()} }); - c.SwaggerDoc("v1", new OpenApiInfo { Title = "妙语", Version = "v1" }); + c.SwaggerDoc("v1", new OpenApiInfo { Title = "妙语", Version = assemblyInfo.Version, Description = assemblyInfo.Description }); foreach (var assemblies in AppDomain.CurrentDomain.GetAssemblies()) { // 添加 XML 注释文件路径 @@ -112,7 +114,7 @@ app.UseExceptionMiddleware(); app.MapGet("/", () => "请求成功").WithName("默认请求"); var startDateTime = DateTime.Now; -var InformationalVersion = Assembly.GetEntryAssembly().GetCustomAttribute().InformationalVersion; +//var InformationalVersion = Assembly.GetEntryAssembly().GetCustomAttribute().InformationalVersion; //Console.WriteLine($"version:{InformationalVersion}"); app.MapGet("/system", () => { @@ -124,8 +126,8 @@ app.MapGet("/system", () => long memoryUsage = currentProcess.WorkingSet64; return new { - msg = $"系统版本:{InformationalVersion},启动时间:{startDateTime.ToString("yyyy-MM-dd HH:mm:ss")},已安全运行时间:{DateTime.Now.Subtract(startDateTime).TotalMinutes.ToString("#.##")}分钟", - InformationalVersion, + msg = $"系统信息:{assemblyInfo.InformationalVersion},启动时间:{startDateTime.ToString("yyyy-MM-dd HH:mm:ss")},已安全运行时间:{DateTime.Now.Subtract(startDateTime).TotalMinutes.ToString("0.##")}分钟", + assemblyInfo, startDateTime, MemoryUsage = $"{memoryUsage / (1024.0 * 1024.0):F2}MB", CPUUsage = $"{cpuUsage:F2}%"