【发布时间】:2018-11-22 15:49:21
【问题描述】:
我创建了一个 C# 项目 (C# 7.0 & .net framework 4.7.2) 并添加了一些单元测试 (NUnit 3.11.0)。
此代码存储在 Gitlab 存储库中,我可以在本地运行测试和构建。但现在我想通过 Gitlab CI 自动执行此操作。根据thisstackoverflow 帖子和互联网上的许多文章,您应该在 Windows 机器上创建自己的运行器。
但是大多数答案已经很老了,Gitlab CI 现在可以使用 Docker 映像了。但后来我遇到了我的问题。我应该为这个跑步者使用什么图像?我试过microsoft/dotnet-framework 和microsoft/dotnet,但这些都不起作用。
microsoft/dotnet-framework 给出错误信息:No such image: microsoft/dotnet-framework
并且microsoft/dotnet 图像不包含.net 4.7.2 库,因此它不能用于构建。
Gitlab CI + Docker 镜像 + C# 构建?
是否仍然无法为 C# 构建(控制台应用程序)创建带有 Docker 映像的 Gitlab CI 运行器?或者我只是在这里做错了什么?
我当前的 .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.
【问题讨论】:
-
microsoft/图像是 Windows 图像。您需要寻找基于 linux 的 c# builder 映像。 -
dsfnctnl/gitlab-dotnetcore-builder? (我没有测试过)
-
@tkausl 啊,这证实了我的想法。那么我可能应该寻找带有 Mono 的 Linux 映像。
-
@AndreasZita,谢谢! (未找到清单 -->)nvm。必须添加特定的版本号。
-
@Mr.wiseguy - 我找到了使用 Mono 图像的解决方案。我使用 Mono 图像为构建管道编写了 GitLab CICD 配置。我将其发布为答案。如果你觉得有用,请告诉我
标签: c# .net docker gitlab gitlab-ci