Integrate GitVersion and add version provider abstraction
- Added GitVersion for semantic versioning and build metadata - Introduced IVersionProvider and VersionProvider for UI-friendly version display - MainForm now uses IVersionProvider for version label - Registered VersionProvider in DI container - Improved logging: filtered out AutoMapper license logs - General code cleanup in Program.cs
This commit is contained in:
parent
5cb491f1b5
commit
509d5357a8
8 changed files with 154 additions and 44 deletions
9
MaddoShared/IVersionProvider.cs
Normal file
9
MaddoShared/IVersionProvider.cs
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
namespace MaddoShared;
|
||||
|
||||
public interface IVersionProvider
|
||||
{
|
||||
/// <summary>
|
||||
/// Returns a human-friendly version string for display (prefer AssemblyInformationalVersion).
|
||||
/// </summary>
|
||||
string GetVersionString();
|
||||
}
|
||||
60
MaddoShared/VersionProvider.cs
Normal file
60
MaddoShared/VersionProvider.cs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
using System.Diagnostics;
|
||||
using System.Reflection;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace MaddoShared;
|
||||
|
||||
public sealed class VersionProvider : IVersionProvider
|
||||
{
|
||||
public string GetVersionString()
|
||||
{
|
||||
// Prefer the entry assembly; fall back to executing assembly
|
||||
var asm = Assembly.GetEntryAssembly() ?? Assembly.GetExecutingAssembly();
|
||||
|
||||
// 1) AssemblyInformationalVersion
|
||||
var infoAttr = asm.GetCustomAttribute<AssemblyInformationalVersionAttribute>();
|
||||
if (!string.IsNullOrWhiteSpace(infoAttr?.InformationalVersion))
|
||||
{
|
||||
return infoAttr.InformationalVersion!;
|
||||
}
|
||||
|
||||
// 2) File product version
|
||||
try
|
||||
{
|
||||
var location = asm.Location;
|
||||
if (!string.IsNullOrWhiteSpace(location))
|
||||
{
|
||||
var fvi = FileVersionInfo.GetVersionInfo(location);
|
||||
if (!string.IsNullOrWhiteSpace(fvi.ProductVersion))
|
||||
return fvi.ProductVersion!;
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
// ignore and fall back to assembly version
|
||||
}
|
||||
|
||||
// 3) AssemblyName.Version formatted (avoid -1 and trailing .0 parts)
|
||||
var ver = asm.GetName().Version;
|
||||
if (ver is not null)
|
||||
{
|
||||
// Build a list of parts but ignore negative values
|
||||
var parts = new List<int> { ver.Major, ver.Minor };
|
||||
if (ver.Build >= 0) parts.Add(ver.Build);
|
||||
if (ver.Revision >= 0) parts.Add(ver.Revision);
|
||||
|
||||
// Trim trailing zeros but keep at least major.minor
|
||||
for (int i = parts.Count - 1; i > 1; i--)
|
||||
{
|
||||
if (parts[i] == 0)
|
||||
parts.RemoveAt(i);
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
return string.Join('.', parts);
|
||||
}
|
||||
|
||||
return "0.0.0";
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue