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

d5vmydt9  于 2022-12-07  发布在  Git
关注(0)|答案(2)|浏览(125)

我正在用Xamarin.Forms做一个我喜欢的项目,我想知道是否有人有成功配置gitlab-ci.yml构建的经验。关于配置.NET构建的材料似乎很有限,在把两个构建串在一起之前,我试着成功地构建一个。我试过per-project .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
eblbsuwk

eblbsuwk1#

是的,我们让它完美地工作,而不需要使用引导程序或AzureDevops。正如@AkashKava所提到的,我必须让它在Mac构建代理/运行程序上运行,我使用AppCenter's CLI commands作为它的分发部分,我还在那里存储我的证书、密钥库和配置文件。
因此,在运行所有程序之前,请确保恢复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}替换为您的应用程序的文件夹名称/应用程序名称,这在我的案例中是相同的。

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的一些工作。

cngwdvgl

cngwdvgl2#

还没有,不幸的是,你将需要一个windows机器,先决条件:

  • windows
  • 耶! .NET Framework只在Windows操作系统中工作,所以你要使用的机器需要使用Windows。
  • Git
  • 你认为我们需要安装Git吗?好吧,那是个笑话,很明显我们需要Git,顺便说一下,我们要使用GitLab!
  • MSBuild版本
  • 为了能够生成和发布我们的应用程序,我们需要安装MSBuild。

您可以从here获取更多关于在.Net上构建新Xamarin表单的信息。

相关问题