Table of Contents

VersionConversionOptions Class

Definition

Namespace
Codebelt.Extensions.Asp.Versioning
Assemblies
Codebelt.Extensions.Asp.Versioning.dll
Source
src/Codebelt.Extensions.Asp.Versioning/VersionConversionOptions.cs

Provides programmatic configuration for version conversion operations.

public class VersionConversionOptions : IValidatableParameterObject, IParameterObject
Inheritance
VersionConversionOptions
Implements

Examples

Use VersionConversionOptions to control how a .NET Version is translated into a SemanticApiVersion by SemanticApiVersion.FromVersion. The options let callers decide whether the Revision component is folded into the build metadata and which identifier labels that segment. Configure a VersionConversionOptions instance, validate it with ValidateOptions, then pass it through the Action<VersionConversionOptions> overload of SemanticApiVersion.FromVersion. The example below opts into revision mapping and renames the build-metadata key to build, so a four-part Version(1, 2, 3, 4) renders as 1.2.3+build.4.

using System;
using Codebelt.Extensions.Asp.Versioning;

namespace Codebelt.Extensions.Asp.Versioning;

public class SemanticVersionFromVersionSetup
{
    public string ConvertAssemblyVersionToSemantic()
    {
        var options = new VersionConversionOptions
        {
            IncludeRevision = true,
            RevisionIdentifier = "build"
        };

        var assemblyVersion = new Version(1, 2, 3, 4);
        return SemanticApiVersion.FromVersion(assemblyVersion, o =>
        {
            o.IncludeRevision = options.IncludeRevision;
            o.RevisionIdentifier = options.RevisionIdentifier;
        }).ToString();
    }
}

Remarks

This class is used to configure how .NET Version objects are converted to semantic API versions.

Constructors

Name Description
VersionConversionOptions()

Initializes a new instance of the VersionConversionOptions class.

Properties

Name Description
IncludeRevision

Gets or sets a value indicating whether the Revision component should be included in the converted semantic version.

RevisionIdentifier

Gets or sets the identifier to use for the revision component when included in the semantic version build metadata.

Methods

Name Description
ValidateOptions()

Validates the current state of the options.

See Also