Public/Set-CCProjectVersion.ps1

function Set-CCProjectVersion {
    <#
    .SYNOPSIS
        Writes a version into every manifest that states one. Supports -WhatIf.
    .DESCRIPTION
        The git tag is the version, and a manifest repeats the latest tag. Publish-CCRelease writes the
        manifests as part of a release. This command is for the other case: bringing a manifest that has
        drifted back to its tag.
    .EXAMPLE
        Set-CCProjectVersion -Path . -Version (Get-CCProjectVersion).Version
    .EXAMPLE
        Set-CCProjectVersion -Path . -Version 2.0.0 -WhatIf
    #>

    [CmdletBinding(SupportsShouldProcess, ConfirmImpact = 'Medium')]
    [OutputType([pscustomobject])]
    param(
        [Parameter(Position = 0)]
        [string]$Path = '.',

        [Parameter(Mandatory)]
        [string]$Version
    )

    $full = (Resolve-Path -LiteralPath $Path).Path
    $service = [CodeCompass.Core.VersionService]::new()
    $target = [CodeCompass.Core.Versioning.SemanticVersion]::Parse($Version)
    $current = $service.GetVersion($full)
    $manifests = @($current.Manifests)
    $previous = if ($manifests.Count -gt 0) { $manifests[0].Value } else { $current.Version.ToString() }

    if ($PSCmdlet.ShouldProcess($current.Context.RootPath, "Set manifest version $previous -> $target")) {
        $change = $service.SetVersion($full, $target)
        [pscustomobject]@{
            Previous   = $change.Previous.ToString()
            New        = $change.New.ToString()
            Technology = $change.Context.Technology.ToString()
        }
    }
    else {
        [pscustomobject]@{
            Previous   = $previous
            New        = $target.ToString()
            Technology = $current.Context.Technology.ToString()
            WhatIf     = $true
        }
    }
}