C# on .NET Core

How to build a C# project in Codefresh

Codefresh can work with any .NET core application very easily as there are official Docker images from Microsoft.

The example C# project

You can see the example project at https://github.com/dotnet-architecture/eShopOnWeb. The repository contains a C# Web project with 3 kinds of tests. It has different tags for each version of .NET Core and has

  • a docker-compose.yml file for local development
  • a tests directory with all types of tests
  • a Dockerfile at /src/Web

There are also previous releases at https://github.com/dotnet-architecture/eShopOnWeb/releases.

Create a CI pipeline for C# applications

Creating a CI/CD pipeline for C# is very easy, because Codefresh can run any SDK image version that you wish.

Compiling a C# application in a pipeline

Compiling a C# application in a pipeline

Here is the full pipeline that compiles the application after checking out the code.

codefresh.yml

version: '1.0'
stages:
  - checkout
  - test
  - build
steps:
  main_clone:
    title: Cloning main repository...
    stage: checkout
    type: git-clone
    repo: 'dotnet-architecture/eShopOnWeb'
    revision: 'netcore3.0'
    git: github-1
  my_unit_tests:
    title: Unit tests
    stage: test
    image: mcr.microsoft.com/dotnet/core/sdk:3.0
    working_directory: './tests/UnitTests/'
    commands:
      - dotnet test
  my_integration_tests:
    title: Integration tests
    stage: test
    image: mcr.microsoft.com/dotnet/core/sdk:3.0
    working_directory: './tests/IntegrationTests/'
    commands:
      - dotnet test 
  my_functional_tests:
    title: Fuctional tests
    stage: test
    image: mcr.microsoft.com/dotnet/core/sdk:3.0
    working_directory: './tests/FunctionalTests/'
    commands:
      - dotnet test 
  my_app_docker_image:
    title: Building Docker Image
    type: build
    stage: build
    image_name: dotnetcore-eshop
    working_directory: ./
    tag: latest
    dockerfile: src/Web/Dockerfile      

This pipeline:

  1. clones the source code
  2. Uses the official mcr.microsoft.com/dotnet/core/sdk:3.0 image to run unit/integration/functional tests in 3 different folders
  3. Builds the application docker image using the root folder as Docker context but with the Dockerfile located at ./src/Web

You can see the resulting image in the image dashboard:

Building a .NET core docker image

Building a .NET core docker image

C/C++ examples
Codefresh YAML for pipeline definitions
Steps in pipelines
Creating pipelines
How Codefresh pipelines work