Prefer GitVersion values for assembly and publish versioning
Enhance versioning by prioritizing GitVersion output for assembly, file, and informational versions. Add fallback MSBuild target to run GitVersion CLI in Visual Studio builds. Update publish rename logic to use FullSemVer and improve version normalization for artifact naming.
This commit is contained in:
parent
69fdf01de3
commit
a00ab074c4
1 changed files with 28 additions and 4 deletions
|
|
@ -49,6 +49,17 @@
|
||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<!-- If GitVersion ran and produced values, prefer them for assembly/file/informational version
|
||||||
|
so the built assembly exposes FullSemVer for runtime and the publish rename uses the same value. -->
|
||||||
|
<PropertyGroup>
|
||||||
|
<!-- AssemblyVersion uses AssemblySemVer when available (three-part) -->
|
||||||
|
<AssemblyVersion Condition="'$(GitVersion_AssemblySemVer)' != ''">$(GitVersion_AssemblySemVer)</AssemblyVersion>
|
||||||
|
<!-- FileVersion uses GitVersion FileVersion when available -->
|
||||||
|
<FileVersion Condition="'$(GitVersion_FileVersion)' != ''">$(GitVersion_FileVersion)</FileVersion>
|
||||||
|
<!-- Prefer FullSemVer for informational version -->
|
||||||
|
<InformationalVersion Condition="'$(GitVersion_FullSemVer)' != ''">$(GitVersion_FullSemVer)</InformationalVersion>
|
||||||
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Update="Properties\Settings.Designer.cs">
|
<Compile Update="Properties\Settings.Designer.cs">
|
||||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||||
|
|
@ -63,19 +74,32 @@
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<PropertyGroup />
|
<PropertyGroup />
|
||||||
|
|
||||||
|
<!-- When building inside Visual Studio (which runs .NET Framework MSBuild), the GitVersion.MsBuild
|
||||||
|
task (net8.0) may fail. Run the GitVersion CLI as a fallback to produce obj/gitversion.json so
|
||||||
|
subsequent targets can consume the same values. Developers should install the global tool:
|
||||||
|
dotnet tool install __global GitVersion.Tool __version 6.5.1
|
||||||
|
-->
|
||||||
|
<Target Name="RunGitVersionCliForVisualStudio" BeforeTargets="GenerateAssemblyInfo" Condition="'$(BuildingInsideVisualStudio)' == 'true'">
|
||||||
|
<Message Text="Building inside Visual Studio: attempting to run GitVersion CLI to generate obj\gitversion.json (if `dotnet-gitversion` is installed)." Importance="High" />
|
||||||
|
<!-- Try the typical global tool command. ContinueOnError=true so VS build doesn't fail if CLI is not installed. -->
|
||||||
|
<Exec Command="dotnet-gitversion -output file -outputfile "$(ProjectDir)obj\gitversion.json"" ContinueOnError="true" />
|
||||||
|
<!-- Also try 'dotnet tool run' in case a local tool manifest is used. -->
|
||||||
|
<Exec Command="dotnet tool run GitVersion.Tool -- -output file -outputfile "$(ProjectDir)obj\gitversion.json"" ContinueOnError="true" />
|
||||||
|
</Target>
|
||||||
|
|
||||||
<!-- After publish, rename the produced executable to ImageCatalog.<year>.<major>.<minor>.<build>.<revision>.<ext>
|
<!-- 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).
|
The destination extension is taken from the actual produced file (exe or dll).
|
||||||
-->
|
-->
|
||||||
<Target Name="RenamePublishedExeWithYearAndVersion" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
|
<Target Name="RenamePublishedExeWithYearAndVersion" AfterTargets="Publish" Condition="'$(PublishDir)' != ''">
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<_PublishYear>$([System.DateTime]::Now.ToString("yyyy"))</_PublishYear>
|
<_PublishYear>$([System.DateTime]::Now.ToString("yyyy"))</_PublishYear>
|
||||||
<!-- Prefer FileVersion (four-part) then AssemblyVersion -->
|
<!-- Prefer GitVersion FullSemVer, then FileVersion, then AssemblyVersion -->
|
||||||
<_Ver>$(FileVersion)</_Ver>
|
<_Ver Condition="'$(GitVersion_FullSemVer)' != ''">$(GitVersion_FullSemVer)</_Ver>
|
||||||
|
<_Ver Condition="'$(GitVersion_FullSemVer)' == ''">$(FileVersion)</_Ver>
|
||||||
<_Ver Condition="'$(_Ver)' == ''">$(AssemblyVersion)</_Ver>
|
<_Ver Condition="'$(_Ver)' == ''">$(AssemblyVersion)</_Ver>
|
||||||
|
|
||||||
<!-- Normalize to avoid plus signs and spaces -->
|
<!-- Normalize to avoid spaces but keep plus signs for pre-release build metadata; replace spaces with underscore -->
|
||||||
<_VerSanitized>$([System.String]::Copy('$(_Ver)'))</_VerSanitized>
|
<_VerSanitized>$([System.String]::Copy('$(_Ver)'))</_VerSanitized>
|
||||||
<_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace('+', '.'))</_VerSanitized>
|
|
||||||
<_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace(' ', '_'))</_VerSanitized>
|
<_VerSanitized>$([System.String]::Copy('$(_VerSanitized)').Replace(' ', '_'))</_VerSanitized>
|
||||||
|
|
||||||
<_NewExeNameBase>ImageCatalog.$(_PublishYear).$(_VerSanitized)</_NewExeNameBase>
|
<_NewExeNameBase>ImageCatalog.$(_PublishYear).$(_VerSanitized)</_NewExeNameBase>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue