33using Nuke . Common ;
44using Nuke . Common . IO ;
55using Nuke . Common . Tools . DotNet ;
6+ using Nuke . Common . Tools . GitVersion ;
67using Nuke . Common . Utilities ;
78using Nuke . Common . Utilities . Collections ;
89using Serilog ;
@@ -16,13 +17,26 @@ partial class Build
1617{
1718 string BranchName ;
1819 string SemVer ;
20+ AssemblyVersion MainVersion ;
1921
2022 Target CalculateNugetVersion => _ => _
2123 . Unlisted ( )
2224 . Executes ( ( ) =>
2325 {
26+ string preRelease = "-CI" ;
27+ if ( GitHubActions == null )
28+ {
29+ preRelease = "-DEV" ;
30+ }
31+ else if ( GitHubActions . Ref . StartsWith ( "refs/tags/" , StringComparison . OrdinalIgnoreCase ) )
32+ {
33+ int preReleaseIndex = GitHubActions . Ref . IndexOf ( '-' ) ;
34+ preRelease = preReleaseIndex > 0 ? GitHubActions . Ref [ preReleaseIndex ..] : "" ;
35+ }
36+
2437 SemVer = GitVersion . SemVer ;
2538 BranchName = GitVersion . BranchName ;
39+ MainVersion = AssemblyVersion . FromGitVersion ( GitVersion , preRelease ) ;
2640
2741 if ( GitHubActions ? . IsPullRequest == true )
2842 {
@@ -77,16 +91,29 @@ partial class Build
7791
7892 ReportSummary ( s => s
7993 . WhenNotNull ( SemVer , ( summary , semVer ) => summary
80- . AddPair ( "Version" , semVer + preRelease ) ) ) ;
94+ . AddPair ( "Version" , MainVersion . FileVersion + MainVersion . PreRelease ) ) ) ;
8195
8296 DotNetBuild ( s => s
8397 . SetProjectFile ( Solution )
8498 . SetConfiguration ( Configuration )
8599 . EnableNoLogo ( )
86100 . EnableNoRestore ( )
87- . SetVersion ( SemVer + preRelease )
88- . SetAssemblyVersion ( GitVersion . AssemblySemVer )
89- . SetFileVersion ( GitVersion . AssemblySemFileVer )
90- . SetInformationalVersion ( GitVersion . InformationalVersion ) ) ;
101+ . SetVersion ( MainVersion . FileVersion + MainVersion . PreRelease )
102+ . SetAssemblyVersion ( MainVersion . FileVersion )
103+ . SetFileVersion ( MainVersion . FileVersion )
104+ . SetInformationalVersion ( MainVersion . InformationalVersion ) ) ;
91105 } ) ;
106+
107+ public record AssemblyVersion ( string FileVersion , string InformationalVersion , string PreRelease )
108+ {
109+ public static AssemblyVersion FromGitVersion ( GitVersion gitVersion , string preRelease )
110+ {
111+ if ( gitVersion is null )
112+ {
113+ return null ;
114+ }
115+
116+ return new AssemblyVersion ( gitVersion . AssemblySemVer , gitVersion . InformationalVersion , preRelease ) ;
117+ }
118+ }
92119}
0 commit comments