.gitlab-ci.yml for C# using Docker image mono

.gitlab-ci.yml for C# using Docker image mono

我正在尝试设置 gitlab-ci runner 来构建 c# 应用程序。已经设置 gitlab, gitlab-ci, docker, runnermono image

我正在尝试 xbuild example.sln 但需要 nuget packages 并且我不知道如何。

我的 .gitlab-ci.yml 目前看起来像这样。它将进入构建但缺少包的错误。

before_script:

build:
 script:
    - xbuild  "example.sln"

在之前的脚本中,您需要安装和 运行 nuget 命令行客户端,就像您使用 bash 所做的一样,以便在构建项目之前获取依赖项。

编辑:好的 nuget 已经安装在官方单声道图像上,所以你应该这样做:

before_script:
    - nuget restore -NonInteractive

build:
 script:
    - xbuild  "example.sln"

不确定 nuget 命令,因为我不熟悉 C# 和 Mono

我花了一些时间才弄清楚如何 运行 NUnit 测试,特别是因为来自 Gitlab 的 Mono 模板不再是最新的,因此我不得不找出通往 nuget 的正确路径包裹:

image: mono:latest

stages:
  - build
  - test

build:
  stage: build
  script:
  - nuget restore
  - MONO_IOMAP=case xbuild /t:Build /p:Configuration="Release" /p:Platform="Any CPU" MyPlugin.sln

test:
  stage: test
  script:
  - nuget restore
  - MONO_IOMAP=case xbuild /t:Build /p:Configuration="Release" /p:Platform="Any CPU" MyPlugin.sln
  - mono /root/.nuget/packages/nunit.consolerunner/3.9.0/tools/nunit3-console.exe Plugin.Tests/bin/Release/Plugin.Tests.dll