mirror of
https://github.com/waynebian01/Shigure.git
synced 2026-09-03 07:15:24 +08:00
30 lines
901 B
C#
30 lines
901 B
C#
using System.Reflection;
|
|
|
|
namespace Shigure;
|
|
|
|
/// <summary>
|
|
/// 应用版本信息的单一来源。优先取 csproj 的 <Version>(AssemblyInformationalVersion),
|
|
/// 退化到 AssemblyVersion。
|
|
/// </summary>
|
|
internal static class AppInfo
|
|
{
|
|
public static string Version { get; } = ResolveVersion();
|
|
|
|
private static string ResolveVersion()
|
|
{
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
var informational = assembly
|
|
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?
|
|
.InformationalVersion;
|
|
|
|
if (!string.IsNullOrWhiteSpace(informational))
|
|
{
|
|
// 去掉构建元数据后缀(如 "1.1.0+abc123")。
|
|
var plus = informational.IndexOf('+');
|
|
return plus >= 0 ? informational[..plus] : informational;
|
|
}
|
|
|
|
return assembly.GetName().Version?.ToString() ?? "未知";
|
|
}
|
|
}
|