Modernize versioning and display in app and build output

- Switch to explicit "3.2.0" next-version in GitVersion.yml
- Update NuGet packages and set assembly name to "ImageCatalog"
- Add MSBuild target to rename published exe with year and version
- Add AppVersion property to DataModel, set via IVersionProvider
- Replace static version label with data-bound versionLabel in UI
- Remove manual version label logic from MainForm
- Update DI to inject IVersionProvider into DataModel
- Ensures UI always shows correct version and builds are versioned
This commit is contained in:
MaddoScientisto 2026-02-14 22:18:56 +01:00
commit 69fdf01de3
6 changed files with 106 additions and 21 deletions

View file

@ -45,7 +45,7 @@ namespace ImageCatalog_2
public DataModel(ITestService testService, ISettingsService settingsService,
ImageCreationStuff imageCreationService, PicSettings picSettings,
IMapper mapper, ILogger<DataModel> logger)
IMapper mapper, ILogger<DataModel> logger, MaddoShared.IVersionProvider? versionProvider = null)
{
_service = testService;
_logger = logger;
@ -53,6 +53,8 @@ namespace ImageCatalog_2
_imageCreationService = imageCreationService;
_picSettings = picSettings;
_mapper = mapper;
// Populate AppVersion from version provider when available
AppVersion = versionProvider?.GetVersionString() ?? string.Empty;
TestCommand = new RelayCommand(Test);
AsyncTestCommand = new AsyncCommand(TestAsync);
@ -1123,6 +1125,17 @@ namespace ImageCatalog_2
{
await _settingsService.LoadSettingsAsync(filePath, this);
}
private string _appVersion = string.Empty;
public string AppVersion
{
get => _appVersion;
set
{
_appVersion = value;
NotifyPropertyChanged();
}
}
}
}

View file

@ -10,7 +10,8 @@
<FileVersion>3.1.2.0</FileVersion>
<InformationalVersion>3.1.2</InformationalVersion>
<Version>3.1.2</Version>
<AssemblyName>ImageCatalog2025</AssemblyName>
<!-- Default assembly name for regular builds -->
<AssemblyName>ImageCatalog</AssemblyName>
<LangVersion>default</LangVersion>
<ApplicationIcon>Logo.ico</ApplicationIcon>
</PropertyGroup>
@ -40,10 +41,10 @@
</ItemGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="16.0.0" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.2" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="9.0.7" />
<PackageReference Include="GitVersion.MsBuild" Version="5.11.0" PrivateAssets="all" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="10.0.3" />
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="10.0.3" />
<PackageReference Include="GitVersion.MsBuild" Version="6.5.1" PrivateAssets="all" />
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.421302">
<PrivateAssets>all</PrivateAssets>
</PackageReference>
@ -61,4 +62,62 @@
</EmbeddedResource>
</ItemGroup>
<PropertyGroup />
<!-- After publish, rename the produced executable to ImageCatalog.<year>.<major>.<minor>.<build>.<revision>.<ext>
The destination extension is taken from the actual produced file (exe or dll).
-->
<Target Name="RenamePublishedExeWithYearAndVersion" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
<PropertyGroup>
<_PublishYear>$([System.DateTime]::Now.ToString("yyyy"))</_PublishYear>
<!-- Prefer FileVersion (four-part) then AssemblyVersion -->
<_Ver>$(FileVersion)</_Ver>
<_Ver Condition="'$(_Ver)' == ''">$(AssemblyVersion)</_Ver>
<!-- Normalize to avoid plus signs and spaces -->
<_VerSanitized>$([System.String]::Copy('$(_Ver)'))</_VerSanitized>
<_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace('+', '.'))</_VerSanitized>
<_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace(' ', '_'))</_VerSanitized>
<_NewExeNameBase>ImageCatalog.$(_PublishYear).$(_VerSanitized)</_NewExeNameBase>
</PropertyGroup>
<Message Text="Attempting to find published assembly to rename to $(_NewExeNameBase).* in $(PublishDir)" Importance="High" />
<!-- Candidate locations in order of likelihood -->
<PropertyGroup>
<_Candidate1>$(PublishDir)$(TargetFileName)</_Candidate1>
<_Candidate2>$(PublishDir)$(TargetName)$(TargetExt)</_Candidate2>
<_Candidate3>$(PublishDir)$(TargetName).exe</_Candidate3>
<_Candidate4>$(PublishDir)$(AssemblyName)$(TargetExt)</_Candidate4>
<_Candidate5>$(PublishDir)$(AssemblyName).exe</_Candidate5>
</PropertyGroup>
<!-- Pick the first existing candidate and compute destination using its extension -->
<PropertyGroup Condition="Exists('$(_Candidate1)') and '$(_CandidateFound)' == ''">
<_CandidateFound>$(_Candidate1)</_CandidateFound>
</PropertyGroup>
<PropertyGroup Condition="Exists('$(_Candidate2)') and '$(_CandidateFound)' == ''">
<_CandidateFound>$(_Candidate2)</_CandidateFound>
</PropertyGroup>
<PropertyGroup Condition="Exists('$(_Candidate3)') and '$(_CandidateFound)' == ''">
<_CandidateFound>$(_Candidate3)</_CandidateFound>
</PropertyGroup>
<PropertyGroup Condition="Exists('$(_Candidate4)') and '$(_CandidateFound)' == ''">
<_CandidateFound>$(_Candidate4)</_CandidateFound>
</PropertyGroup>
<PropertyGroup Condition="Exists('$(_Candidate5)') and '$(_CandidateFound)' == ''">
<_CandidateFound>$(_Candidate5)</_CandidateFound>
</PropertyGroup>
<!-- If a candidate was found, compute destination using its extension and perform copy/delete -->
<PropertyGroup Condition="'$(_CandidateFound)' != ''">
<_FoundExt>$([System.IO.Path]::GetExtension('$(_CandidateFound)'))</_FoundExt>
<_DestExe>$(PublishDir)$(_NewExeNameBase)$(_FoundExt)</_DestExe>
</PropertyGroup>
<Message Text="Found candidate: $(_CandidateFound). Renaming to $(_DestExe)" Importance="High" Condition="'$(_CandidateFound)' != ''" />
<Copy SourceFiles="$(_CandidateFound)" DestinationFiles="$(_DestExe)" SkipUnchangedFiles="false" Condition="'$(_CandidateFound)' != ''" />
<Delete Files="$(_CandidateFound)" Condition="'$(_CandidateFound)' != ''" />
</Target>
</Project>

View file

@ -171,7 +171,7 @@ namespace ImageCatalog
Label29 = new Label();
Label30 = new Label();
PictureBox3 = new PictureBox();
_Label27 = new Label();
versionLabel = new Label();
_Button7 = new Button();
_Button5 = new Button();
Label20 = new Label();
@ -1748,15 +1748,16 @@ namespace ImageCatalog
PictureBox3.TabStop = false;
PictureBox3.Visible = false;
//
// _Label27
// versionLabel
//
_Label27.Location = new Point(1182, 873);
_Label27.Margin = new Padding(6, 0, 6, 0);
_Label27.Name = "_Label27";
_Label27.Size = new Size(281, 47);
_Label27.TabIndex = 62;
_Label27.Text = "Versione 2.2 2021";
_Label27.TextAlign = ContentAlignment.MiddleRight;
versionLabel.Location = new Point(1182, 873);
versionLabel.Margin = new Padding(6, 0, 6, 0);
versionLabel.Name = "versionLabel";
versionLabel.Size = new Size(281, 47);
versionLabel.TabIndex = 62;
versionLabel.Text = "Versione 2.2 2021";
versionLabel.TextAlign = ContentAlignment.MiddleRight;
versionLabel.DataBindings.Add(new Binding("Text", bindingSource1, "AppVersion", true));
//
// _Button7
//
@ -1872,7 +1873,7 @@ namespace ImageCatalog
Controls.Add(CheckBox22);
Controls.Add(Label43);
Controls.Add(TabControl1);
Controls.Add(_Label27);
Controls.Add(versionLabel);
Controls.Add(_Button7);
Controls.Add(_Button5);
Controls.Add(Label20);
@ -1997,6 +1998,7 @@ namespace ImageCatalog
internal Label Label41;
internal TextBox TextBox31;
internal TextBox TextBox30;
internal Label versionLabel;
internal GroupBox GroupBox9;
internal CheckBox CheckBox17;
internal CheckBox CheckBox16;

View file

@ -32,7 +32,7 @@ public partial class MainForm
private readonly PicSettings _picSettings;
public MainForm(DataModel model, ImageCreationStuff imageCreationStuff, PicSettings picSettings,
ParametriSetup parametriSetup, ILogger<MainForm> logger, IVersionProvider versionProvider)
ParametriSetup parametriSetup, ILogger<MainForm> logger)
{
Model = model;
_parametriSetup = parametriSetup;
@ -55,8 +55,7 @@ public partial class MainForm
btnOpenSourceFolder.Click += BtnOpenSourceFolder_Click;
btnOpenDestFolder.Click += BtnOpenDestFolder_Click;
var versionString = versionProvider?.GetVersionString() ?? "0.0.0";
_Label27.Text = $"Version: {versionString}";
// Version label is data-bound to DataModel.AppVersion; DataModel is populated with the version via DI
}
protected void BindControls()

View file

@ -87,7 +87,19 @@ static class Program
services.AddTransient<ITestService, TestService>();
services.AddTransient<ISettingsService, SettingsService>();
services.AddTransient<DataModel>();
services.AddTransient<DataModel>(sp =>
{
// Resolve optional version provider and pass to DataModel
var testService = sp.GetRequiredService<ITestService>();
var settingsService = sp.GetRequiredService<ISettingsService>();
var imageCreation = sp.GetRequiredService<ImageCreationStuff>();
var picSettings = sp.GetRequiredService<PicSettings>();
var mapper = sp.GetRequiredService<IMapper>();
var logger = sp.GetRequiredService<ILogger<DataModel>>();
var versionProvider = sp.GetService<MaddoShared.IVersionProvider>();
return new DataModel(testService, settingsService, imageCreation, picSettings, mapper, logger, versionProvider);
});
services.AddTransient<ImageCreationStuff>();
services.AddTransient<ImageCreatorSharp>();