From cf24ef3b56a899c8c450f324be4bf4d77bc65f4d Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Fri, 19 Oct 2018 16:36:30 -0700 Subject: [PATCH] Add a few properties for easier processing at the command line Closes #233 --- src/NerdBank.GitVersioning/VersionOracle.cs | 28 ++++++++++++++++++--- 1 file changed, 24 insertions(+), 4 deletions(-) diff --git a/src/NerdBank.GitVersioning/VersionOracle.cs b/src/NerdBank.GitVersioning/VersionOracle.cs index f4f73f27..6fd30b24 100644 --- a/src/NerdBank.GitVersioning/VersionOracle.cs +++ b/src/NerdBank.GitVersioning/VersionOracle.cs @@ -98,7 +98,7 @@ public VersionOracle(string projectDirectory, LibGit2Sharp.Repository repo, LibG this.VersionHeightOffset = this.VersionOptions?.BuildNumberOffsetOrDefault ?? 0; - this.PrereleaseVersion = ReplaceMacros(this.VersionOptions?.Version.Prerelease ?? string.Empty); + this.PrereleaseVersion = this.ReplaceMacros(this.VersionOptions?.Version.Prerelease ?? string.Empty); this.CloudBuildNumberOptions = this.VersionOptions?.CloudBuild?.BuildNumberOrDefault ?? VersionOptions.CloudBuildNumberOptions.DefaultInstance; @@ -186,10 +186,15 @@ public IEnumerable BuildMetadataWithCommitId public bool PublicRelease { get; set; } /// - /// Gets the prerelease version information. + /// Gets the prerelease version information, including a leading hyphen. /// public string PrereleaseVersion { get; } + /// + /// Gets the prerelease version information, omitting the leading hyphen, if any. + /// + public string PrereleaseVersionNoLeadingHyphen => this.PrereleaseVersion?.TrimStart('-'); + /// /// Gets the version information without a Revision component. /// @@ -203,13 +208,28 @@ public IEnumerable BuildMetadataWithCommitId public int BuildNumber => Math.Max(0, this.Version.Build); /// - /// Gets or sets the major.minor version string. + /// Gets the component of the . + /// + public int VersionRevision => this.Version.Revision; + + /// + /// Gets the major.minor version string. /// /// /// The x.y string (no build number or revision number). /// public Version MajorMinorVersion => new Version(this.Version.Major, this.Version.Minor); + /// + /// Gets the component of the . + /// + public int VersionMajor => this.Version.Major; + + /// + /// Gets the component of the . + /// + public int VersionMinor => this.Version.Minor; + /// /// Gets the Git revision control commit id for HEAD (the current source code version). /// @@ -355,7 +375,7 @@ public IEnumerable BuildMetadataWithCommitId private string SemVer2BuildMetadata => (this.PublicRelease ? string.Empty : this.GitCommitIdShortForNonPublicPrereleaseTag) + FormatBuildMetadata(this.BuildMetadata); - private string PrereleaseVersionSemVer1 => MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, SemVer1NumericIdentifierPadding); + private string PrereleaseVersionSemVer1 => MakePrereleaseSemVer1Compliant(this.PrereleaseVersion, this.SemVer1NumericIdentifierPadding); private string GitCommitIdShortForNonPublicPrereleaseTag => (string.IsNullOrEmpty(this.PrereleaseVersion) ? "-" : ".") + $"g{this.GitCommitIdShort}";