Gitlab CI与C#构建

7
我创建了一个C#项目 (C# 7.0 & .net framework 4.7.2) 并添加了一些单元测试 (NUnit 3.11.0)。这段代码存储在Gitlab仓库中,我可以在本地运行测试和构建。但现在我想通过Gitlab CI自动化这个过程。根据这篇stackoverflow文章和互联网上的许多文章,您应该在Windows机器上创建自己的runner。
但是大多数答案已经相当陈旧了,Gitlab CI现在可以使用Docker镜像。但是我遇到了问题。我应该为此runner使用哪个镜像?我尝试了microsoft/dotnet-frameworkmicrosoft/dotnet,但它们都无法正常工作。 microsoft/dotnet-framework会显示错误消息:No such image: microsoft/dotnet-frameworkmicrosoft/dotnet镜像不包含.net 4.7.2库,因此无法用于构建。

Gitlab CI + Docker镜像 + C#构建?

是否仍然无法创建一个使用Docker镜像进行C#构建 (控制台应用程序)的Gitlab CI runner?还是我在这里做错了什么?

我的当前 .gitlab-ci.yml 文件

image: microsoft/dotnet-framework

stages:
  - build

before_script:
  - 'dotnet restore'

app-build:
  stage: build
  script:
    - 'dotnet build'
  only:
    - master

更新

感谢 @Andreas Zita,我现在有一个镜像(dsfnctnl/gitlab-dotnetcore-builder:0.15.0)。不幸的是,这给我带来了与 microsoft/dotnet 相同的错误。这可能是我的构建脚本中的错误(或者我希望是这样),但我似乎找不到它在哪里。

错误信息:

$ dotnet restore
  Nothing to do. None of the projects specified contain packages to restore.
$ dotnet build
Microsoft (R) Build Engine version 15.9.20+g88f5fadfbe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Nothing to do. None of the projects specified contain packages to restore.
/usr/share/dotnet/sdk/2.1.500/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/builds/test/TestProject.csproj]
/usr/share/dotnet/sdk/2.1.500/Microsoft.Common.CurrentVersion.targets(1179,5): error MSB3644: The reference assemblies for framework ".NETFramework,Version=v4.7.2" were not found. To resolve this, install the SDK or Targeting Pack for this framework version or retarget your application to a version of the framework for which you have the SDK or Targeting Pack installed. Note that assemblies will be resolved from the Global Assembly Cache (GAC) and will be used in place of reference assemblies. Therefore your assembly may not be correctly targeted for the framework you intend. [/builds/test/TestProjectTests.csproj]

Build FAILED.

1
microsoft/镜像是Windows镜像。您需要寻找基于Linux的C#构建器镜像。 - tkausl
@AndreasZita,谢谢!(manifest not found -->)没事了。我必须添加一个特定的版本号。 - Mr.wiseguy
@Mr.wiseguy - 你上面的问题解决了吗?如果是,请发布你的答案。我也在做同样的事情。使用GitLab实现控制台应用程序的CI/CD,并部署到AWS EC2 Windows服务器。 - Gaurav Upadhyay
嗨@GauravUpadhyay,很遗憾我没有找到解决问题的方法。Docker镜像不包含.NET框架,因此无法通过镜像构建应用程序。我还没有花时间创建包含框架的Docker镜像。 - Mr.wiseguy
1
@Mr.wiseguy - 我通过 Mono image 找到了解决方案。我编写了 GitLab CICD 配置以便使用 Mono image 进行构建流水线。我将其作为答案发布。如果您发现有用,请告诉我。 - Gaurav Upadhyay
显示剩余3条评论
2个回答

2

0

在GitLab中,使用单色图像能够帮助我构建C#应用程序。

    image: mono:4.4.0.182

     stages:
      - build
    app-build:
      stage: build
      script:
        - MONO_IOMAP=case xbuild/t:Build/p:Configuration="Debug"/p:Platform="x86"
          myApp.sln
    only:
       - master

根据构建配置,平台可能会发生变化,例如AnyCPU。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接