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

Sha*_*bot 11 xamarin gitlab-ci xamarin.forms

我正在与Xamarin.Forms合作开展一个宠物项目,我想知道是否有人有成功配置gitlab-ci.yml构建的经验.一般来说,配置.NET构建的材料似乎有限,在将两个版本串联起来之前,试着成功构建一个.已经尝试了每个项目.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
Run Code Online (Sandbox Code Playgroud)

Saa*_*mer 6

是的,我们让它完美工作,无需使用 boots 或 AzureDevops。正如 @AkashKava 提到的,我必须让它在 Mac 构建代理/运行器上运行,并且我使用AppCenter 的 CLI 命令来进行分发部分,我还存储了我的证书、密钥库和配置文件。

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

before_script:
  - nuget restore
Run Code Online (Sandbox Code Playgroud)

然后,创建 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
Run Code Online (Sandbox Code Playgroud)

只需将 {AppName} 替换为您的应用程序的文件夹名称/应用程序名称,这在我的情况下是相同的。对于 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"

Run Code Online (Sandbox Code Playgroud)

请注意,在 下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}
Run Code Online (Sandbox Code Playgroud)

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

    - appcenter distribute release --app {CompanyInAppCenter}/{iOSAppNameInAppCenter} --group "Collaborators" --file {AppName}.iOS/bin/iPhone/QA/{AppName}.ipa --token=${APPCENTER_API_TOKEN}
Run Code Online (Sandbox Code Playgroud)

PS:我写了一篇文章,介绍如何使用 GitHub Actions而不使用您自己的构建代理来完成其中一些工作。