Skip to content

Instantly share code, notes, and snippets.

@BurgerZ
Created June 24, 2020 09:54
Show Gist options
  • Save BurgerZ/05a1d648aa7851aeb72646fe4d145e31 to your computer and use it in GitHub Desktop.
Save BurgerZ/05a1d648aa7851aeb72646fe4d145e31 to your computer and use it in GitHub Desktop.

Revisions

  1. @campbellja campbellja renamed this gist Aug 31, 2016. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. @campbellja campbellja revised this gist Aug 31, 2016. No changes.
  3. @campbellja campbellja created this gist Aug 31, 2016.
    68 changes: 68 additions & 0 deletions .ps1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,68 @@
    $majorMinorVersion = ""
    $commitCount = & git rev-list --count HEAD
    Write-Output "git rev-list --count HEAD = $commitCount"


    $params = @{
    FilePath = ""
    OS = ""
    ToolsDir = ""
    SolutionFolder = ""
    VersionSpecFilePath = ""
    BuildCounter = $commitCount
    SetBuildNumber = "%mr.Build.Version.SetTCBuildNumber%"
    }



    if(![System.IO.File]::Exists($params.FilePath)){
    Write-Error "$params.FilePath does not exist"
    exit
    }


    $version = Retrieve-Version-From-Spec-File
    -Path $params.VersionSpecFilePath `
    -BuildCount $params.BuildCounter `

    Write-Host "##teamcity[buildNumber '$($version.PackageVersion)']"

    $fileXml = [xml] (Get-Content $params.FilePath )

    $versionNumber = $version.PackageVersion
    $buildCounter = $params.BuildCounter

    if($params.OS -eq "iOS"){

    Write-Output "Writing to $filePath - setting CFBundleVersion to $versionNumber"

    Select-Xml -xml $fileXml -XPath "//dict/key[. = 'CFBundleShortVersionString']/following-sibling::string[1]" |
    %{
    $_.Node.InnerXml = $versionNumber
    }

    Select-Xml -xml $fileXml -XPath "//dict/key[. = 'CFBundleVersion']/following-sibling::string[1]" |
    %{
    $_.Node.InnerXml = $buildCounter
    }
    }
    elseif($params.OS -eq "Android"){
    $xpath = "//manifest"
    Write-Output "Writing to $filePath - setting manifest.android:versionCode to $versionNumber"

    Select-Xml -xml $fileXml -XPath $xpath |
    %{
    $_.Node.SetAttribute("android:versionName", $versionNumber)
    $_.Node.SetAttribute("android:versionCode", $buildCounter)
    }
    }
    else{
    Write-Error "Unrecognised OS argument: $params.OS"
    exit
    }

    $fileXml.Save($params.FilePath)
    Write-Output "Writing Version ($version.PackageVersion) to BuildVersion.txt"

    $version.PackageVersion | Out-File BuildVersion.txt