Types/OpenPackage/get_Version.ps1

<#
.SYNOPSIS
    Gets OpenPackage `Version`
.DESCRIPTION
    Gets the OpenPackage `Version` property.

    If this has not been explicitly set, looks for potential version information in:

    * PowerShell Manifests
    * package.json
    * nuspec files
.LINK
    https://learn.microsoft.com/en-us/dotnet/api/system.io.packaging.packageproperties.version?wt.mc_id=MVP_321542
#>

param()

if ($this.PackageProperties.Version) {
    return $this.PackageProperties.Version
}

$moduleManifest = @($this.PowerShellManifest)[0]
if ($moduleManifest) {
    $this.PackageProperties.Version = $moduleManifest.ModuleVersion
    return $this.PackageProperties.Version
}

$packageJson = @($this.'Package.json')[0]
if ($packageJson -and $packageJson.version) {
    $this.PackageProperties.Version = $packageJson.version
    return $this.PackageProperties.Version
}

$nuSpec = @($this.nuSpec)[0]
if ($nuSpec -and $nuSpec.package.metadata.version) {
    $this.PackageProperties.Version =
        $nuSpec.package.metadata.version

    return $this.PackageProperties.Version
}