tasks/versioning.tasks.ps1

# Control flags
$SkipGitVersion = $false
$GitVersionConfig = "$here/GitVersion.yml"

# Options
$GitVersionToolVersion = "5.8.0"

# Synopsis: Run GitVersion tool
task GitVersion -If {!$SkipGitVersion} {
    Install-DotNetTool -Name "GitVersion.Tool" -Version $GitVersionToolVersion
    Write-Build Cyan "GitVersion Config: $GitVersionConfig"
    $gitVersionOutputJson = exec { dotnet-gitversion /output json /nofetch /config $GitVersionConfig }
    
    Write-Build Cyan "GitVersion Output:`n$gitVersionOutputJson"

    $env:GitVersionOutput = $gitVersionOutputJson
    $script:GitVersion = $gitVersionOutputJson | ConvertFrom-Json -AsHashtable

    # Set the native GitVersion output as environment variables and build server variables
    Write-Warning "The emitting of GitVersion-related build server variables without a 'GitVersion.' prefix is now deprecated and will be removed in a future release"
    foreach ($var in $script:GitVersion.Keys) {
        Set-Item -Path "env:GITVERSION_$var" -Value $GitVersion[$var]
        Set-BuildServerVariable -Name "GitVersion.$var" -Value $GitVersion[$var]

        # TODO: Remove this in a future release
        Set-BuildServerVariable -Name $var -Value $GitVersion[$var]
    }
}