@@ -68,6 +68,7 @@ private enum ExitCodes
6868 PackageIdNotFound ,
6969 ShallowClone ,
7070 InternalError ,
71+ InvalidTagNameSetting ,
7172 }
7273
7374 private static bool AlwaysUseLibGit2 => string . Equals ( Environment . GetEnvironmentVariable ( "NBGV_GitEngine" ) , "LibGit2" , StringComparison . Ordinal ) ;
@@ -545,6 +546,24 @@ private static Task<int> OnTagCommand(string project, string versionOrRef)
545546 return Task . FromResult ( ( int ) ExitCodes . NoGitRepo ) ;
546547 }
547548
549+ // get tag name format
550+ VersionOptions versionOptions = context . VersionFile . GetVersion ( ) ;
551+ if ( versionOptions is null )
552+ {
553+ Console . Error . WriteLine ( $ "Failed to load version file for directory '{ searchPath } '.") ;
554+ return Task . FromResult ( ( int ) ExitCodes . NoVersionJsonFound ) ;
555+ }
556+
557+ string tagNameFormat = versionOptions . TagNameOrDefault ;
558+
559+ // ensure there is a '{version}' placeholder in the tag name
560+ if ( string . IsNullOrEmpty ( tagNameFormat ) || ! tagNameFormat . Contains ( "{version}" ) )
561+ {
562+ Console . Error . WriteLine ( $ "Invalid 'tagName' setting '{ tagNameFormat } '. Missing version placeholder '{{version}}'.") ;
563+ return Task . FromResult ( ( int ) ExitCodes . InvalidTagNameSetting ) ;
564+ }
565+
566+ // get commit to tag
548567 LibGit2Sharp . Repository repository = context . Repository ;
549568 if ( ! context . TrySelectCommit ( versionOrRef ) )
550569 {
@@ -585,8 +604,12 @@ private static Task<int> OnTagCommand(string project, string versionOrRef)
585604 return Task . FromResult ( ( int ) ExitCodes . NoVersionJsonFound ) ;
586605 }
587606
588- oracle . PublicRelease = true ; // assume a public release so we don't get a redundant -gCOMMITID in the tag name
589- string tagName = $ "v{ oracle . SemVer2 } ";
607+ // assume a public release so we don't get a redundant -gCOMMITID in the tag name
608+ oracle . PublicRelease = true ;
609+
610+ // replace the "{version}" placeholder with the actual version
611+ string tagName = tagNameFormat . Replace ( "{version}" , oracle . SemVer2 ) ;
612+
590613 try
591614 {
592615 context . ApplyTag ( tagName ) ;
0 commit comments