DependencyVersionRange Class

Describes a range of plug-in versions.

The format of string representation of the range is generally the same as for NuGet <PackageReference> element, see Version ranges in the NuGet documentation.

There are the following differences in behavior from NuGet:

  1. Semantic Versioning is not supported by DependencyVersionRange because plug-in versions are represented by the standard System.Version class and IComponentInfo.Version properties.

    Retrieval of plug-in version from AssemblyVersionAttribute and FileVersionInfo is also the reason why the ranges of versions are validated using only full 4-part versions. For example, version range [1.*, 1.0.0.0) is considered invalid on parse because it can denote only inconsistent range [1.0.0.0, 1.0.0.0) during load of the plug-in assemblies.

  2. Lower bound must always be specified in DependencyVersionRange and it must be inclusive, i.e., version ranges like (1.3.0, 2.0] or [,1.5] are considered invalid on parse.

    The reason of this behavior is NuGet Warning NU1604 which says that project dependency should contain an inclusive lower bound. In fact an inclusive lower bound always exists for dependencies between plug-ins because the actual version of dependency is resolved during compiltation of the depending plug-in.

    However, the use of pattern as inclusive lower bound is allowed: [1.*, 2.0) is considered a valid range.

  3. Infinite upper bound must be exclusive in DependencyVersionRange so ranges like [3.7,] are considered invalid on parse.

Definition

Namespace: SMath.Extensibility.Setup
Assembly: SMath.Manager (in SMath.Manager.dll) Version: 1.74.9654.0
C#
public sealed class DependencyVersionRange : IEquatable<DependencyVersionRange>
Inheritance
Object    DependencyVersionRange
Implements
IEquatableDependencyVersionRange

Remarks

The following types of input strings are considered valid by both NuGet.Versioning and parser of DependencyVersionRange:

<version or pattern>
[<version>]
[<version or pattern>,)
[<min version or pattern>,<max version>] if at least one full (4-part) version falls into the range.
[<min version or pattern>,<max version>) if at least one full (4-part) version falls into the range.

The following types of input strings are considered invalid by both NuGet.Versioning and parser of DependencyVersionRange:

[<version>) because it always matches an empty set of versions.
(<version>] because it always matches an empty set of versions.
(<version>) because it always matches an empty set of versions.
[<pattern>] because upper bound must not be a pattern.
[<pattern>) because upper bound must not be a pattern.
(<pattern>] because upper bound must not be a pattern.
(<pattern>) because upper bound must not be a pattern.
[<min version or pattern>,<max version>] when none of full (4-part) versions fall into the range.
[<min version or pattern>,<max version>) when none of full (4-part) versions fall into the range.
[<min version or pattern>,<max pattern>] because upper bound must not be a pattern.
[<min version or pattern>,<max pattern>) because upper bound must not be a pattern.
(<min version or pattern>,<max pattern>] because upper bound must not be a pattern.
(<min version or pattern>,<max pattern>) because upper bound must not be a pattern.

The following types of input strings are considered valid by NuGet.Versioning, however they are considered invalid by parser of DependencyVersionRange:

[<version or pattern>,] because infinite upper bound must be exclusive.
(<version or pattern>,] because lower bound must be inclusive and infinite upper bound must be exclusive.
(<version or pattern>,) because lower bound must be inclusive.
(<min version or pattern>,<max version>] because lower bound must be inclusive.
(<min version or pattern>,<max version>) because lower bound must be inclusive.

Constructors

DependencyVersionRange Constructs an instance of DependencyVersionRange.

Properties

IsMaxInclusive Determines whether MaxVersion is included into the range.
IsMaxLimited Returns when the range has upper limit, i.e., when MaxVersion is not .
MaxVersion Maximal version in the range or if the version has no upper limit. This value is never a pattern.
MinVersion Minimal version in the range or a pattern of the minimal version. This value is never .
OriginalString The original string value which has been parsed during construction of the range or if the range is not parsed from string.

Methods

Contains Checks whether the specified version is within the range.
Equals(DependencyVersionRange)Indicates whether the current object is equal to another object of the same type.
Equals(Object)Determines whether the specified object is equal to the current object.
(Overrides ObjectEquals(Object))
GetHashCodeServes as the default hash function.
(Overrides ObjectGetHashCode)
GetTypeGets the Type of the current instance.
(Inherited from Object)
Parse

Parses DependencyVersionRange from the specified string. Throws ArgumentException if the input string cannot be parsed.

See details on format of input which is supported by this method in the Remarks section for DependencyVersionRange.

ToStringReturns a string that represents the current object.
(Overrides ObjectToString)
ToString(Int32, Boolean)

Returns string representation of DependencyVersionRange using the specified number of significant version parts and with optional simplification.

The significantVersionParts argument is handled in the following way:

significantVersionPartsBehavior
0Version part is written unless its value is Empty.
1 - 4 Trailing zeros are added to the resulting string if the actual number of version parts is less than significantVersionParts. If all part values after significantVersionParts are zeros then they are not added to the output. The output is not affected when IsPattern is .

When the simplify argument is the resulting string is simplified in the following way:

Full StringSimplified String
[*, )*
[<expr, expr>][<expr>]

  Tip

Call this method with significantVersionParts = 3 and simplify = to get the default string representation of the version range in NuGet.

TryParse

Attempts to parse DependencyVersionRange from the specified string.

See details on format of input which is supported by this method in the Remarks section for DependencyVersionRange.

See Also