使用C#构建的Gitlab CI

时间:2018-11-22 15:49:21

标签: c# .net docker gitlab gitlab-ci

我创建了一个C#项目(C# 7.0.net framework 4.7.2),还添加了一些单元测试(NUnit 3.11.0)。

此代码存储在Gitlab存储库中,我可以运行测试并在本地构建。但是现在我想通过Gitlab CI来自动化它。根据{{​​3}} stackoverflow的帖子和互联网上的许多文章,您应该在Windows计算机上创建自己的运行程序。

但是大多数答案已经相当老了,Gitlab CI现在可以使用Docker映像了。但是后来我遇到了问题。我应该为该跑步者使用什么图像?我已经尝试过thismicrosoft/dotnet-framework,但是这些都不起作用。

microsoft/dotnet-framework给出错误消息:No such image: microsoft/dotnet-framework

并且microsoft/dotnet图像不包含.net 4.7.2库,因此不能用于构建。


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

是否仍然无法使用Docker映像为C#构建(控制台应用程序)创建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.

2 个答案:

答案 0 :(得分:0)

Mono映像正在帮助我在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)进行更改。

答案 1 :(得分:0)

我认为,如果您使用.net Framework 4.7.2并希望轻松构建,则需要Windows和Visual Studio MSBuild。 也许有帮助:https://medium.com/@n3d4ti/build-net-project-with-gitlab-ci-44e6c3562a8