SemanticVersion class
Namespace: Velopack
A semantic version implementation that supports SemVer2 with an optional 4th revision component for backwards compatibility with NuGet-style version numbers.
public class SemanticVersion : IEquatable<SemanticVersion>, IComparable<SemanticVersion>, IComparable
Implements: IEquatable<SemanticVersion>, IComparable<SemanticVersion>, IComparable
Constructors
| Constructor | Summary |
|---|---|
SemanticVersion | Creates a new SemanticVersion. |
SemanticVersion | Creates a new SemanticVersion from a traditional 4-part Version. |
SemanticVersion | Creates a new SemanticVersion with a revision component. |
SemanticVersion(major, minor, patch, prerelease, metadata)
public SemanticVersion(int major, int minor, int patch, string prerelease = "", string metadata = "")
Creates a new SemanticVersion.
Parameters
| Name | Type | Description |
|---|---|---|
major | int | The major version number. |
minor | int | The minor version number. |
patch | int | The patch version number. |
prerelease | string | The pre-release label (e.g. "beta.1"), or empty/null for a stable release. |
metadata | string | The build metadata string, or empty/null for no metadata. |
SemanticVersion(version, prerelease, metadata)
public SemanticVersion(Version version, string prerelease = "", string metadata = "")
Creates a new SemanticVersion from a traditional 4-part Version.
Parameters
| Name | Type | Description |
|---|---|---|
version | Version | The version containing major, minor, patch, and revision. |
prerelease | string | The pre-release label (e.g. "beta.1"), or empty/null for a stable release. |
metadata | string | The build metadata string, or empty/null for no metadata. |
SemanticVersion(major, minor, patch, revision, prerelease, metadata)
public SemanticVersion(int major, int minor, int patch, int revision, string prerelease = "", string metadata = "")
Creates a new SemanticVersion with a revision component.
Parameters
| Name | Type | Description |
|---|---|---|
major | int | The major version number. |
minor | int | The minor version number. |
patch | int | The patch version number. |
revision | int | The fourth version component. |
prerelease | string | The pre-release label, or empty/null for a stable release. |
metadata | string | The build metadata string, or empty/null for no metadata. |
Properties
| Property | Summary |
|---|---|
Major | The major version component. |
Minor | The minor version component. |
Patch | The patch version component. |
Revision | The optional fourth version component, or 0 if not specified. |
Version | A basic four-part version ignoring release labels and metadata. |
Release | The full pre-release label string (e.g. "beta.1"), or empty string if not a pre-release. |
ReleaseLabels | The dot-separated pre-release identifiers. |
IsPrerelease | True if this version has a pre-release label. |
Metadata | The build metadata string, or empty string if none. |
HasMetadata | True if this version has build metadata. |
Major
public int Major { get; }
The major version component.
Minor
public int Minor { get; }
The minor version component.
Patch
public int Patch { get; }
The patch version component.
Revision
public int Revision { get; }
The optional fourth version component, or 0 if not specified.
Version
public Version Version { get; }
A basic four-part version ignoring release labels and metadata.
Release
public string Release { get; }
The full pre-release label string (e.g. "beta.1"), or empty string if not a pre-release.
ReleaseLabels
public IEnumerable<string> ReleaseLabels { get; }
The dot-separated pre-release identifiers.
IsPrerelease
public bool IsPrerelease { get; }
True if this version has a pre-release label.
Metadata
public string Metadata { get; }
The build metadata string, or empty string if none.
HasMetadata
public bool HasMetadata { get; }
True if this version has build metadata.
Methods
| Method | Summary |
|---|---|
Parse | Parse a version string into a SemanticVersion. Throws ArgumentException on invalid input. |
TryParse | Try to parse a version string. Returns false if the string is not a valid semantic version. |
CompareByVersion | Compares two versions by Major.Minor.Patch.Revision only, ignoring pre-release and metadata. |
ToFullString | Returns the full version string including metadata (e.g. "1.2.3-beta+build"). |
ToNormalizedString | Returns the normalized version string without metadata (e.g. "1.2.3-beta"). |
ToString | |
CompareTo | |
CompareTo | |
Equals | |
Equals | |
GetHashCode |
Parse(value)
public static SemanticVersion Parse(string value)
Parse a version string into a SemanticVersion. Throws ArgumentException on invalid input.
Parameters
| Name | Type | Description |
|---|---|---|
value | string |
Returns SemanticVersion
TryParse(value, version)
public static bool TryParse(string? value, out SemanticVersion? version)
Try to parse a version string. Returns false if the string is not a valid semantic version.
Parameters
| Name | Type | Description |
|---|---|---|
value | string | |
version | SemanticVersion |
Returns bool
CompareByVersion(a, b)
public static int CompareByVersion(SemanticVersion? a, SemanticVersion? b)
Compares two versions by Major.Minor.Patch.Revision only, ignoring pre-release and metadata.
Parameters
| Name | Type | Description |
|---|---|---|
a | SemanticVersion | |
b | SemanticVersion |
Returns int
ToFullString()
public string ToFullString()
Returns the full version string including metadata (e.g. "1.2.3-beta+build").
Returns string
ToNormalizedString()
public string ToNormalizedString()
Returns the normalized version string without metadata (e.g. "1.2.3-beta").
Returns string
ToString()
public override string ToString()
Returns string
CompareTo(other)
public int CompareTo(SemanticVersion? other)
Parameters
| Name | Type | Description |
|---|---|---|
other | SemanticVersion |
Returns int
CompareTo(obj)
public int CompareTo(object? obj)
Parameters
| Name | Type | Description |
|---|---|---|
obj | object |
Returns int
Equals(other)
public bool Equals(SemanticVersion? other)
Parameters
| Name | Type | Description |
|---|---|---|
other | SemanticVersion |
Returns bool
Equals(obj)
public override bool Equals(object? obj)
Parameters
| Name | Type | Description |
|---|---|---|
obj | object |
Returns bool
GetHashCode()
public override int GetHashCode()
Returns int
Operators
| Operator | Summary |
|---|---|
operator == | Equality operator. |
operator != | Inequality operator. |
operator < | Less-than operator. |
operator > | Greater-than operator. |
operator <= | Less-than-or-equal operator. |
operator >= | Greater-than-or-equal operator. |
operator ==(left, right)
public static bool operator ==(SemanticVersion? left, SemanticVersion? right)
Equality operator.
Parameters
| Name | Type | Description |
|---|---|---|
left | SemanticVersion | |
right | SemanticVersion |
Returns bool
operator !=(left, right)
public static bool operator !=(SemanticVersion? left, SemanticVersion? right)
Inequality operator.
Parameters
| Name | Type | Description |
|---|---|---|
left | SemanticVersion | |
right | SemanticVersion |
Returns bool
operator <(left, right)
public static bool operator <(SemanticVersion? left, SemanticVersion? right)
Less-than operator.
Parameters
| Name | Type | Description |
|---|---|---|
left | SemanticVersion | |
right | SemanticVersion |
Returns bool
operator >(left, right)
public static bool operator >(SemanticVersion? left, SemanticVersion? right)
Greater-than operator.
Parameters
| Name | Type | Description |
|---|---|---|
left | SemanticVersion | |
right | SemanticVersion |
Returns bool
operator <=(left, right)
public static bool operator <=(SemanticVersion? left, SemanticVersion? right)
Less-than-or-equal operator.
Parameters
| Name | Type | Description |
|---|---|---|
left | SemanticVersion | |
right | SemanticVersion |
Returns bool
operator >=(left, right)
public static bool operator >=(SemanticVersion? left, SemanticVersion? right)
Greater-than-or-equal operator.
Parameters
| Name | Type | Description |
|---|---|---|
left | SemanticVersion | |
right | SemanticVersion |
Returns bool
Generated from Velopack 1.1.1