Exemplo n.º 1
0
 /// <summary>
 /// Gets the standard Informational version string.
 /// If <see cref="SVersion.IsValid"/> is false this throws an <see cref="InvalidOperationException"/>:
 /// the constant <see cref="InformationalVersion.ZeroInformationalVersion"/> should be used when IsValid is false.
 /// </summary>
 /// <param name="commitSha">The SHA1 of the commit (must be 40 hex digits).</param>
 /// <param name="commitDateUtc">The commit date (must be in UTC).</param>
 /// <returns>The informational version.</returns>
 public string GetInformationalVersion(string commitSha, DateTime commitDateUtc)
 {
     if (!IsValid)
     {
         throw new InvalidOperationException("IsValid must be true. Use InformationalVersion.ZeroInformationalVersion when IsValid is false.");
     }
     return(InformationalVersion.BuildInformationalVersion(this, commitSha, commitDateUtc));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Parses the given string. Throws an <see cref="ArgumentException"/> if the syntax is invalid.
        /// To avoid exception, simply use the <see cref="InformationalVersion"/> constructor.
        /// </summary>
        /// <param name="s">The string to parse.</param>
        /// <returns>A <see cref="IsValidSyntax"/> informational version.</returns>
        static public InformationalVersion Parse(string?s)
        {
            var i = new InformationalVersion(s);

            if (!i.IsValidSyntax)
            {
                throw new ArgumentException(i.ParseErrorMessage, nameof(s));
            }
            return(i);
        }
        /// <summary>
        /// Gets the standard Informational version string.
        /// If <see cref="SVersion.IsValid"/> is false this throws an <see cref="InvalidOperationException"/>:
        /// the constant <see cref="InformationalVersion.ZeroInformationalVersion"/> should be used when IsValid is false.
        /// </summary>
        /// <param name="commitSha">The SHA1 of the commit (must be 40 hex digits).</param>
        /// <param name="commitDateUtc">The commit date (must be in UTC).</param>
        /// <param name="buildInfo">
        /// Not null for post-release version.
        /// <see cref="CIBuildDescriptor.IsValid"/> and <see cref="CIBuildDescriptor.IsValidForShortForm"/> must be true.
        /// </param>
        /// <returns>The informational version.</returns>
        public string GetInformationalVersion(string commitSha, DateTime commitDateUtc, CIBuildDescriptor buildInfo = null)
        {
            if (!IsValid)
            {
                throw new InvalidOperationException("IsValid must be true. Use CSVersion.InvalidInformationalVersion when IsValid is false.");
            }
            var semVer   = ToString(CSVersionFormat.Normalized, buildInfo);
            var nugetVer = ToString(CSVersionFormat.ShortForm, buildInfo);

            return(InformationalVersion.BuildInformationalVersion(semVer, nugetVer, commitSha, commitDateUtc));
        }