+// ----------------------------------------------
+// START: Version from git tag
+// ----------------------------------------------
+type ReleaseType = Release | Beta | Alpha | ReleaseCandidate
+/// Get the SHA1 for the last available tag or None, if not tags set in repository
+ let gitLastTagShaCommand = "rev-list --tags --max-count=1"
+ let ok,msg,error = runGitCommand "" gitLastTagShaCommand
+ if ok then Some msg.[0] else None
+/// Get the tag name for the given SHA1 commit or None, if no tag for this commit
+let getTagForCommit sha =
+ let gitLastTagCommand = sprintf "describe --tag %s" sha
+ let ok,msg,error = runGitCommand "" gitLastTagCommand
+ if ok then Some (msg |> Seq.head) else None
+/// Get version from the last tag in git or "0.0.0" version as fallback
+ let fallbackVersion = "0.0.0"
+ match getShaFromLastTag with
+ match getTagForCommit s with
+ | None _ -> prefix + fallbackVersion
+ | None _ -> prefix + fallbackVersion
+ if isNullOrEmpty prefix then "^" else sprintf "(?<=^%s){1}" prefix
+ let pattern = sprintf "%s%s" pattern "(\d+\.\d+){1}(\.\d+){0,2}$"
+ let versionRegex = System.Text.RegularExpressions.Regex(pattern)
+ match versionRegex.Match tagVersion with
+ | s when s.Success -> SemVerHelper.parse s.Value
+ | _ -> SemVerHelper.parse fallbackVersion
+ let currentBranch = Git.Information.getBranchName ""
+ match currentBranch with
+ | s when startsWith s "hotfix/" -> ReleaseCandidate
+ | s when startsWith s "release/" -> ReleaseCandidate
+/// Get the version for assembly (+1 on patch level, if not on master)
+let getAssemblyVersion prefix =
+ let version = getLastTag prefix
+ match getReleaseState with
+ | Release -> version.Patch
+ | _ -> version.Patch + 1
+ sprintf "%d.%d.%d.%s" version.Major version.Minor patch buildCounter
+/// Get the version for nuget package (+1 on patch level, if not on master)
+let getNugetVersion prefix =
+ let version = getLastTag prefix
+ let releaseState = getReleaseState
+ match releaseState with
+ | Release -> version.Patch
+ | _ -> version.Patch + 1
+ match releaseState with
+ | Release -> sprintf "%d.%d.%d" version.Major version.Minor patch
+ | s -> sprintf "%d.%d.%d-%A%s" version.Major version.Minor patch s buildCounter
+/// TRUE: stable realease
+ match getReleaseState with
+// ----------------------------------------------
+// END: Version from git tag
+// ----------------------------------------------