Public/Set-CCProjectVersion.ps1

function Set-CCProjectVersion {
    <#
    .SYNOPSIS
        Writes a new version to a project's native source file. Supports -WhatIf.
    .EXAMPLE
        Set-CCProjectVersion -Path . -Version 1.4.0
    .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)

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