【问题标题】:How can I associate the build version generated by VSTS to a release in VS App Center?如何将 VSTS 生成的构建版本关联到 VS App Center 中的发布?
【发布时间】:2018-07-14 17:30:08
【问题描述】:

我开始在我的 VSTS 构建管道中集成 Visual Studio App Center。

设置

在我的 iOS 应用程序构建后,它的二进制文件被发送到 App Center。 App Center 不会构建应用程序:VSTS 会。这是最新版本和版本号的屏幕截图:

在 Visual Studio App Center 中,我无法(重新)使用 VSTS 管道实际生成的版本号。如下图所示,版本值始终为1.0 (1.0)

问题

在 Visual Studio App Center 中,如何将 VSTS 构建中的版本号关联到 VS App Center 中的发布?

【问题讨论】:

    标签: continuous-integration azure-devops visual-studio-app-center


    【解决方案1】:

    Visual Studio App Center 应该直接从二进制文件中获取版本信息。

    就我而言,VSTS 中用于在AssemblyInfo.csInfo.plist 中应用正确版本号的 bash 脚本已损坏(它不再查找文件)。所有生成的二进制文件的版本号为1.0

    修复脚本解决了问题。

    【讨论】:

    • 将此标记为答案,这样我们就知道它已经解决了
    • 我肯定会,但我必须等待 4 小时(嗯.. 现在 2 小时)才能将我自己的答案标记为已解决 :)
    【解决方案2】:

    查看解决方案以防万一Auto incrementing build number for appxbundle package when deploying to appcenter via vsts

    您可以通过 PowerShell 更新版本(将 PowerShell 任务添加到构建定义),示例脚本:UpdateVersion.ps1

    #Based on https://www.visualstudio.com/docs/build/scripts/index
    # Enable -Verbose option
    [CmdletBinding()] 
    
    $VersionRegex = "\d+\.\d+\.\d+\.\d+"
    
    $ManifestVersionRegex = " Version=""\d+\.\d+\.\d+\.\d+"""
    
    if (-not $Env:BUILD_BUILDNUMBER)
    {
        Write-Error ("BUILD_BUILDNUMBER environment variable is missing.")
        exit 1
    }
    Write-Verbose "BUILD_BUILDNUMBER: $Env:BUILD_BUILDNUMBER"
    
    $ScriptPath = $null
    try
    {
        $ScriptPath = (Get-Variable MyInvocation).Value.MyCommand.Path
        $ScriptDir = Split-Path -Parent $ScriptPath
    }
    catch {}
    
    if (!$ScriptPath)
    {
        Write-Error "Current path not found!"
        exit 1
    }
    
    # Get and validate the version data
    $VersionData = [regex]::matches($Env:BUILD_BUILDNUMBER,$VersionRegex)
    switch($VersionData.Count)
    {
       0        
          { 
             Write-Error "Could not find version number data in BUILD_BUILDNUMBER."
             exit 1
          }
       1 {}
       default 
          { 
             Write-Warning "Found more than instance of version data in BUILD_BUILDNUMBER." 
             Write-Warning "Will assume first instance is version."
          }
    }
    $NewVersion = $VersionData[0]
    Write-Verbose "Version: $NewVersion"
    
    
    $AssemblyVersion = $NewVersion
    $ManifestVersion = " Version=""$NewVersion"""
    
    Write-Host "Version: $AssemblyVersion"
    Write-Host "Manifest: $ManifestVersion"
    Write-Host "ScriptDir: " $ScriptDir
    
    # Apply the version to the assembly property files
    $assemblyInfoFiles = gci $ScriptDir -recurse -include "*Properties*","My Project" | 
        ?{ $_.PSIsContainer } | 
        foreach { gci -Path $_.FullName -Recurse -include AssemblyInfo.* }
    
    if($assemblyInfoFiles)
    {
        Write-Host "Will apply $AssemblyVersion to $($assemblyInfoFiles.count) Assembly Info Files."
    
        foreach ($file in $assemblyInfoFiles) {
            $filecontent = Get-Content($file)
            attrib $file -r
            $filecontent -replace $VersionRegex, $AssemblyVersion | Out-File $file utf8
    
            Write-Host "$file.FullName - version applied"
        }
    }
    else
    {
        Write-Warning "No Assembly Info Files found."
    }
    
    # Try Manifests
    $manifestFiles = gci .\ -recurse -include "Package.appxmanifest" 
    
    if($manifestFiles)
    {
        Write-Host "Will apply $ManifestVersion to $($manifestFiles.count) Manifests."
    
        foreach ($file in $manifestFiles) {
            $filecontent = Get-Content($file)
            attrib $file -r
            $filecontent -replace $ManifestVersionRegex, $ManifestVersion | Out-File $file utf8
    
            Write-Host "$file.FullName - version applied to Manifest"
        }
    }
    else
    {
        Write-Warning "No Manifest files found."
    }
    
    Write-Host ("##vso[task.setvariable variable=AppxVersion;]$NewVersion")
    

    更多信息,可以参考这篇文章:Set up a continuous deployment build for sideloading

    【讨论】:

    • 我不确定我是否理解这将有什么帮助。看起来它与 AppX 包的版本控制有关(我猜是 UWP 应用程序)。就我而言,我使用 bash 脚本对 iOS 应用程序进行版本控制。不知道App Center怎么获取? App Center 中的 1.0(1.0)从何而来?是不是因为我犯了一个错误,我的应用实际上没有版本控制?
    • 我会被诅咒的。原来我的脚本坏了,没有更新程序集中的版本号。我会修复它,看看是否一切正常。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多