DevOps  

How to Configure CI/CD Pipeline for .NET Project Using GitHub Actions?

Configuring a CI/CD pipeline for a .NET project using GitHub Actions is essential for automating build, test, and deployment workflows in modern DevOps environments. Continuous Integration and Continuous Deployment help teams deliver high-quality ASP.NET Core applications, Web APIs, and microservices with faster release cycles and reduced manual effort. GitHub Actions provides a powerful, cloud-based automation platform that integrates seamlessly with .NET projects hosted in GitHub repositories.

In this article, we will implement a complete CI/CD pipeline for a .NET project using GitHub Actions, covering build automation, unit testing, artifact generation, and deployment strategy.

What Is CI/CD in .NET Projects?

Continuous Integration (CI) ensures that every code change is automatically built and tested. Continuous Deployment (CD) automates the release process to staging or production environments.

In a typical .NET DevOps workflow:

  • Developers push code to GitHub.

  • GitHub Actions triggers a workflow.

  • The project is restored, built, and tested.

  • Artifacts are generated.

  • The application is deployed to a target environment such as Azure App Service.

This automation reduces integration issues and ensures consistent application delivery.

Prerequisites

Before configuring the GitHub Actions pipeline for your .NET project, ensure:

  • A .NET project (ASP.NET Core Web API or MVC application)

  • A GitHub repository

  • .NET SDK version defined in the project

  • Target deployment environment (optional for CD)

Step 1: Create GitHub Actions Workflow File

Inside your repository, create the following folder structure:

.github/workflows/

Create a YAML file named:

ci-cd-dotnet.yml

Step 2: Configure CI Pipeline (Build and Test)

Add the following configuration:

name: .NET CI/CD Pipeline

on:
  push:
    branches: [ "main" ]
  pull_request:
    branches: [ "main" ]

jobs:
  build:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout Repository
      uses: actions/checkout@v4

    - name: Setup .NET
      uses: actions/setup-dotnet@v4
      with:
        dotnet-version: '8.0.x'

    - name: Restore Dependencies
      run: dotnet restore

    - name: Build Project
      run: dotnet build --configuration Release --no-restore

    - name: Run Unit Tests
      run: dotnet test --no-build --verbosity normal

Explanation:

  • actions/checkout pulls the source code.

  • actions/setup-dotnet installs the required .NET SDK.

  • dotnet restore restores NuGet packages.

  • dotnet build compiles the project.

  • dotnet test executes automated tests.

This configuration implements Continuous Integration for your .NET application.

Step 3: Publish Build Artifacts

To prepare the application for deployment, add a publish step:

    - name: Publish Application
      run: dotnet publish -c Release -o ./publish

    - name: Upload Build Artifacts
      uses: actions/upload-artifact@v4
      with:
        name: dotnet-app
        path: ./publish

The publish command generates optimized build output suitable for deployment.

Step 4: Configure Continuous Deployment to Azure App Service

If deploying to Azure App Service, add a deployment job:

  deploy:
    runs-on: ubuntu-latest
    needs: build

    steps:
    - name: Download Build Artifacts
      uses: actions/download-artifact@v4
      with:
        name: dotnet-app

    - name: Deploy to Azure Web App
      uses: azure/webapps-deploy@v2
      with:
        app-name: "your-app-service-name"
        publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
        package: .

Important:

  • Add your Azure publish profile as a GitHub secret named AZURE_WEBAPP_PUBLISH_PROFILE.

  • Store all sensitive credentials inside GitHub Secrets.

Branch-Based Deployment Strategy

For production-ready DevOps pipelines, use environment-based deployment:

  • main → Production

  • develop → Staging

  • feature branches → CI only

You can configure branch filters inside the on section of the workflow YAML.

Best Practices for .NET CI/CD with GitHub Actions

  • Use separate workflows for CI and CD in large projects.

  • Enable caching for NuGet packages to speed up builds.

  • Run code quality checks and static analysis.

  • Integrate security scanning tools.

  • Use environment protection rules in GitHub.

Example of caching dependencies:

    - name: Cache NuGet Packages
      uses: actions/cache@v4
      with:
        path: ~/.nuget/packages
        key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
        restore-keys: |
          ${{ runner.os }}-nuget-

CI/CD Pipeline Architecture Overview

In a professional DevOps setup:

  1. Developer pushes code.

  2. GitHub Actions runs automated build and test.

  3. Artifacts are published.

  4. Deployment job pushes application to Azure.

  5. Monitoring tools track application health.

This ensures reliable and automated software delivery for ASP.NET Core applications.

Conclusion

Configuring a CI/CD pipeline for a .NET project using GitHub Actions enables automated build, testing, and deployment processes that significantly improve software delivery speed and reliability. By integrating restore, build, test, publish, and deployment steps into a structured GitHub workflow, teams can implement a modern DevOps strategy for ASP.NET Core applications. Leveraging GitHub Secrets, artifact management, caching, and environment-based deployment further strengthens security and performance, ensuring scalable and production-ready continuous integration and continuous deployment pipelines for enterprise-grade .NET solutions.