Gitlab CI 和 Xamarin 构建失败

问题描述 投票:0回答:2

我在 Visual Studio for Mac 中创建了一个全新的 Xamarin Forms App 项目,并将其添加到 GitLab 存储库。之后我创建了一个 .gitlab-ci.yml 文件来设置我的 CI 构建。但问题是我收到错误消息:

error MSB4019: The imported project "/usr/lib/mono/xbuild/Xamarin/iOS/Xamarin.iOS.CSharp.targets" was not found. Confirm that the expression in the Import declaration "/usr/lib/mono/xbuild/Xamarin/iOS/Xamarin.iOS.CSharp.targets" is correct, and that the file exists on disk.

Xamarin.Android.Csharp.targets 也会弹出此错误。

我的 YML 文件是这样的:

image: mono:latest

stages:
    - build

build:    
    stage: build
    before_script:
        - msbuild -version
        - 'echo BUILDING'
        - 'echo NuGet Restore'
        - nuget restore 'XamarinFormsTestApp.sln'
    script:        
        - 'echo Cleaning'
        - MONO_IOMAP=case msbuild 'XamarinFormsTestApp.sln' $BUILD_VERBOSITY /t:Clean /p:Configuration=Debug

一些帮助将不胜感激;)

xamarin gitlab mono gitlab-ci gitlab-ci-runner
2个回答
0
投票

您将需要一个 mac 操作系统主机来构建 Xamarin.iOS 应用程序,据我所知,它还不在 GitLab 中。你可以在这里找到讨论私人测试版。现在,我建议您使用自己的 MacOS 主机并在该主机上注册 GitLab runner:

https://docs.gitlab.com/runner/

您可以在您想要的地方设置主机(VM 或物理设备)并在那里安装 GitLab 运行器和 Xamarin 环境,标记它并与 GitLab 管道一起使用,就像与任何其他共享运行器一样。


0
投票

从对您问题的评论来看,Xamarin 似乎在

mono:latest
图像中不可用,但这没关系,因为您可以创建自己的 docker 图像以在 Gitlab CI 中使用。您将需要访问注册表,但如果您使用 gitlab.com(与自托管实例相对),则注册表会为所有用户启用。您可以在文档中找到更多相关信息:https://docs.gitlab.com/ee/user/packages/container_registry/

如果您使用的是自托管,注册表仍然可用(即使是免费版本),但必须由管理员启用(文档在这里:https://docs.gitlab.com/ee/administration/packages/ container_registry.html).

另一种选择是使用 Docker 自己的注册表 Docker Hub。使用哪个注册表并不重要,但您必须能够访问其中之一,以便您的跑步者可以拉下您的形象。如果您使用的是您(或您的管理员)无法直接控制的共享运行器,则尤其如此。如果您可以直接控制您的跑步者,另一种选择是在所有需要它的跑步者上构建 docker 镜像。

我不熟悉 Xamarin,但这里是你如何基于

mono:latest
创建一个新的 Docker 镜像:

# ./mono-xamarin/Dockerfile
FROM mono:latest # this lets us build off of an existing image rather than starting from scratch. Everything in the mono:latest image will be available in this image
RUN ./install_xamarin.sh # Run whatever you need to in order to install xamarin or anything else you need.
RUN apt-get install git # just an example

一旦你的 Dockerfile 写好了,你可以像这样构建它:

docker build --file path/to/Dockerfile --tag mono-xamarin:latest

如果你在你的跑步者身上建立形象,你可以立即使用它,如:

# .gitlab-ci.yml
image: mono-xamarin:latest

stages:
  - build
...

否则,您现在可以将其推送到您想要使用的任何注册表。

© www.soinside.com 2019 - 2024. All rights reserved.