有没有人用gitlab-ci成功搭建了Xamarin.Forms?

Has anyone successfully built Xamarin.Forms with gitlab-ci?

我正在与 Xamarin.Forms 一起开发一个宠物项目,想知道是否有人有成功配置 gitlab-ci.yml 构建的经验。一般而言,.NET 构建的配置似乎受到限制 material,在将两个构建串在一起之前尝试成功构建一个。已尝试将每个项目 .csproj 作为构建路径。

如有任何见解和经验,我们将不胜感激。

当前.gitlab-ci.yml

image: mono

variables:
   Solution: Solution.sln

stages:
  - build
  - test
  - deploy

before_script:
  - nuget restore $Solution

build:
  stage: build
  script:
    - MONO_IOMAP=case xbuild /p:Configuration="Release" /p:Platform="iPhone" /t:Build $Solution

还没有,很遗憾,您将需要一台 windows 机器,先决条件:

  • Windows
    • 是啊! .NET Framework 仅适用于 Windows OS,因此您要使用的机器需要使用 Windows.
  • Git
    • 您认为我们需要安装 Git 吗?好吧,开个玩笑,很明显我们需要 git,顺便说一句,我们将使用 GitLab!
  • MSBuild
    • 为了能够构建和发布我们的应用程序,我们需要安装 MSBuild。

您可以获得有关在新 Xamarin 表单所依赖的 .Net 上构建的更多信息here

是的,我们无需使用引导程序或 AzureDevops 即可完美运行。正如@AkashKava 提到的,我不得不在 Mac 构建 agent/runner 上将其设为 运行,并且我使用 AppCenter's CLI commands 作为它的分发部分,我也将我的证书、密钥库和配置文件。

因此,在一切 运行s 之前,请确保恢复 nuget 包并安装必要的库 nugetmsbuildappcenter、...:

before_script:
  - nuget restore

然后,创建 Android QA apk 文件:

android_dev_apk:
  stage: build
  dependencies: []
  tags:
    - xamarin
  script:
    - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Clean /p:Configuration=Dev
    - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Build /p:Configuration=Dev
    - msbuild {AppName}.Android/{AppName}.Android.csproj $BUILD_VERBOSITY /t:PackageForAndroid /t:SignAndroidPackage /p:Configuration=Dev /p:AndroidKeyStore=True

只需将 {AppName} 替换为您应用的文件夹 name/app 名称,这与我的情况相同。 iOS

同样
ios_qa_app:
  stage: build
  dependencies: []
  tags:
   - xamarin
  script:
   - rm -rf {AppName}.iOS/bin/iPhone/QA
   - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Clean /p:Platform=iPhone /p:Configuration=QA
   - msbuild {AppName}.sln $BUILD_VERBOSITY /t:Build /p:Platform=iPhone /p:ArchiveOnBuild=true /p:Configuration=QA
  artifacts:
    paths:
     - {AppName}.iOS/bin/iPhone/QA/{AppName}.ipa
     - {AppName}.iOS/bin/iPhone/QA/{AppName}.app.dSYM
    expire_in: 10 day
    when: on_success
  only:
    - schedules
  except:
    variables:
      - $ProdBuild == "true"

请注意,在 script 下,一切都像您使用终端时一样,因此您也可以只键入 ls 之类的内容,以打印该文件夹中的文件列表输出日志,或 cd ..cd DirectoryName 更改文件夹。

因此,要分发 Android 工件,请将此添加到您的 Android 脚本中:

    - appcenter distribute release --app {CompanyInAppCenter}/{AndroidAppNameInAppCenter} --group "Collaborators" --file {AppName}.Android/bin/QA/{BundleIdentifier}-Signed.apk --token=${APPCENTER_API_TOKEN}

最后,要分发 iOS 工件,请将此添加到您的 iOS 脚本中:

    - appcenter distribute release --app {CompanyInAppCenter}/{iOSAppNameInAppCenter} --group "Collaborators" --file {AppName}.iOS/bin/iPhone/QA/{AppName}.ipa --token=${APPCENTER_API_TOKEN}

PS:我写了一篇文章,介绍如何在不使用您自己的构建代理的情况下using GitHub Actions做一些这样的事情。