繁体   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