【问题标题】:Auto Increment version number in iOS application using Azure Devops使用 Azure Devops 在 iOS 应用程序中自动增加版本号
【发布时间】:2021-02-02 08:51:22
【问题描述】:

我正在使用 Azure Devops yaml 管道来构建我的 iOS 应用程序。在运行时,我想在 info.plist 文件中每次构建后自动增加 CFBundle 版本号。

例如:版本从 0.0.1 -> 0.0.99 -> 0.1.0 -> 0.1.99 -> 0.2.0 ->............-> 0.99.99 开始-> 1.0.0

关于如何在不使用任何第三方扩展程序的情况下实现这一目标的任何建议? 谢谢!

【问题讨论】:

    标签: azure-devops xamarin.ios azure-pipelines versioning


    【解决方案1】:

    您可以通过在构建应用之前执行 script 步骤来实现。
    此脚本将使用 PlistBuddy 工具读取和递增版本号(假设您在 Azure DevOps 上使用 ma​​cos 计算机)。
    我还假设您正在使用语义版本控制系统 major.minor.patch,如 here 所述。
    该脚本应该按照您的描述增加版本号,然后将其写入应用程序的Info.plist 文件。如果您的项目中有不同的文件,请注意更改该文件的路径

    - script: |
        buildPlist="$(Build.SourcesDirectory)/Info.plist" # Enter the path to your plist file here
        maxSubversionNumber=99 # Set what will be the maximum number to increment each sub version to
    
        versionNumber=$(/usr/libexec/PlistBuddy -c "Print CFBundleShortVersionString" "$buildPlist")
        majorVersion=`echo $versionNumber | awk -F "." '{print ($1 == "" ? 0 : $1)}'`
        minorVersion=`echo $versionNumber | awk -F "." '{print ($2 == "" ? 0 : $2)}'`
        patchVersion=`echo $versionNumber | awk -F "." '{print ($3 == "" ? 0 : $3)}'`
        if [[ $patchVersion -ge $maxSubversionNumber ]]
        then
          patchVersion=0
          if [[ $minorVersion -ge $maxSubversionNumber ]]
          then
            minorVersion=0
            majorVersion=$(($majorVersion + 1))
          else
            minorVersion=$(($minorVersion + 1))
          fi
          else
            patchVersion=$(($patchVersion + 1))
        fi
        newVersionNumber=`echo $versionNumber | awk -F "." '{print '$majorVersion' "." '$minorVersion' ".'$patchVersion'" }'`
        /usr/libexec/PlistBuddy -c "Set :CFBundleShortVersionString $newVersionNumber" "$buildPlist"
    
    

    【讨论】:

    • 嗨@Jobert,有没有办法在不使用 PlistBuddy 工具的情况下实现同样的效果?
    • @SD4 还有其他一些方法。这取决于您在构建机器上拥有的资源。您可以尝试寻找一些 XML 工具来读取和写入版本号。您是否有不能使用 PlistBuddy 的原因?
    • 不,我可以使用 PlistBuddy。只是想知道是否有不同的方法。我去看看谢谢!
    【解决方案2】:

    如果您想保留 $(MARKETING_VERSION) 在 CFBundleShortVersionString 的 Info.plist 但 成功存档或构建后想要增加版本 然后使用以下脚本 以下脚本将像 1.0 一样增加到 2.0 但当然可以使用@Jobert 的解决方案等修改逻辑

    Script to increase app version in Xcode >= 13

    【讨论】:

      猜你喜欢
      • 2019-05-30
      • 2016-07-23
      • 1970-01-01
      • 2019-04-14
      • 2019-01-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多