Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using GitLabCI with C#

I've been working on a C# application and wanted to try the GitLab CI out. All I can see is Ruby and can't find any information on how to build a C# application using it.

When I run the test settings, I make the commit, but I don't have my build.

Enter image description here

How should I make a simple build? Which command could I use for that? I don't mind if I get a failed build (but a build).

like image 805
Andres Rojano Ruiz Avatar asked Nov 04 '15 14:11

Andres Rojano Ruiz


People also ask

Does GitLab support CI CD?

GitLab CI/CD is the part of GitLab that you use for all of the continuous methods (Continuous Integration, Delivery, and Deployment). With GitLab CI/CD, you can test, build, and publish your software with no third-party application or integration needed.

Is GitLab CI CD free?

Anyone using GitHub.com That means anyone using GitHub from personal projects and startups to SMBs can use GitLab CI/CD for free. Starting at 400 free CI pipeline minutes, folks can also add their own Runners or upgrade plans to get more.


3 Answers

I just wanted to share my .gitlab-ci.yml complete with unit testing. You will have to adjust your nuget and possibly other paths. This is for a single project in a solution of the same name.

variables:
  PROJECT_NAME: "ProjectNameGoesHere"
before_script:
  - echo "starting build for %PROJECT_NAME%"
  - echo "Restoring NuGet Packages..."
  - d:\tools\nuget restore "%PROJECT_NAME%.sln"
stages:
  - build
  - test
build:
  stage: build
  script:
  - echo "Release build..."
  - '"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "%PROJECT_NAME%.sln"'
  artifacts:
    untracked: true
test:
  stage: test
  script:
  - echo "starting tests"
  - cd %PROJECT_NAME%Tests/bin/Release
  - '"C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\MSTest.exe" /testcontainer:%PROJECT_NAME%Tests.dll'
  dependencies:
  - build
like image 154
Jeff Avatar answered Oct 14 '22 06:10

Jeff


In order to build a C# application you should have a Windows runner (with shell executor) configured for a project in GitLab CI.

Your .gitlab-ci.yml file should look something like that:

stages:
  - build

job:
  stage: build
  script:
  - echo "Restoring NuGet Packages..."
  - '"c:\nuget\nuget.exe" restore "MySolution.sln"'
  - ''
  - echo "Release build..."
  - C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe /consoleloggerparameters:ErrorsOnly /maxcpucount /nologo /property:Configuration=Release /verbosity:quiet "MySolution.sln"
  tags:
  except:
  - tags

On a Windows machine you need the following tools:

  • Runner installed
  • Git, added to PATH
  • Latest nuget.exe at C:\nuget (or somewhere else. Just make sure you got the path right in the .gitlab-ci.yml file)
like image 43
Grisha Avatar answered Oct 14 '22 07:10

Grisha


The other answers are good. But I'd like to explain how to install a runner in addition. I use my own local system (Windows), so I chose to run shell. But you could use a Docker image if you'd like.

cd C:\Multi-Runner
gitlab-ci-multi-runner register

Please enter the gitlab-ci coordinator URL (e.g. https://gitlab.com )
https://gitlab.com
Please enter the gitlab-ci token for this runner
xxx
Please enter the gitlab-ci description for this runner
my-runner
INFO[0034] fcf5c619 Registering runner... succeeded
Please enter the executor: shell, docker, docker-ssh, ssh?
shell
INFO[0037] Runner registered successfully. Feel free to start it, but if it's
running already the config should be automatically reloaded!

Source: https://gitlab.com/gitlab-org/gitlab-ci-multi-runner/blob/master/docs/install/windows.md

Afterwards, you can use a YAML file a like this:

stages:
    - build
job:
    stage: build
    script: '"C:\Windows\Microsoft.NET\Framework64\v4.0.30319\msbuild.exe" "something.sln"'
like image 10
Prasanth Louis Avatar answered Oct 14 '22 07:10

Prasanth Louis