簡體   English   中英

使用C#構建的Gitlab CI

[英]Gitlab CI with C# build

我創建了一個C#項目( C# 7.0.net framework 4.7.2 ),還添加了一些單元測試( NUnit 3.11.0 )。

此代碼存儲在Gitlab存儲庫中,我可以運行測試並在本地構建。 但是現在我想通過Gitlab CI來自動化它。 根據這篇 stackoverflow帖子以及互聯網上的許多文章,您應該在Windows機器上創建自己的運行程序。

但是其中大多數答案已經相當老了,Gitlab CI現在可以使用Docker映像了。 但是后來我遇到了問題。 我應該為該跑步者使用什么圖像? 我已經嘗試了microsoft / dotnet-frameworkmicrosoft / dotnet,但是這些都不起作用。

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.

Mono image正在幫助我在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)進行更改。

我認為,如果您使用.net framework 4.7.2,並且想要輕松構建,則需要Windows和Visual Studio MSBuild。 也許有幫助: https : //medium.com/@n3d4ti/build-net-project-with-gitlab-ci-44e6c3562a8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM