Delivery & OperationsComplete guide

CI/CD for .NET

A CI/CD pipeline turns ‘it works on my machine’ into a repeatable, observable process: restore, build, test, package, and deploy the same way for every change.

Overview

Continuous integration gives every proposed change fast, repeatable evidence through deterministic restore, compilation, tests, analysis, and security checks. Continuous delivery produces a verified release that is always ready to promote; continuous deployment also performs that promotion automatically when policy passes. A trustworthy .NET pipeline pins tools and dependencies, builds one immutable artifact, attaches source and digest metadata, and promotes the identical bytes through protected environments. Least-privilege identity, isolated untrusted code, observable rollout, database compatibility, and tested rollback make deployment automation safe rather than merely fast.

What you will learn

  • Separate continuous integration, delivery, deployment, and release management.
  • Design a fast .NET verification pipeline with deterministic inputs.
  • Build one immutable artifact and promote it through environments.
  • Apply quality, security, approval, and provenance gates proportionally.
  • Use short-lived workload identity and least-privilege pipeline permissions.
  • Operate deployments with progressive exposure, observability, rollback, and measurable delivery performance.

Prerequisites

  • Git branching, pull requests, and basic GitHub Actions concepts.
  • Ability to restore, build, test, publish, and audit a .NET solution locally.
  • A target environment with a defined deployment and rollback mechanism.

When to use CI/CD for .NET

Good fit

  • Every merge needs consistent automated verification.
  • Releases must be traceable from source to artifact to environment.
  • Teams need repeatable deployment, approval, rollback, and audit evidence.

Choose another approach when

  • Automating an undefined manual process before ownership and rollback are clear.
  • Giving one pipeline broad permanent credentials across all environments.
  • Adding slow gates that do not map to a concrete risk or decision.

Key concepts

Pipeline stages

Restore, build, test, and publish run in order so a fast failure in an early stage avoids wasting time on later ones.

Artifacts

A pipeline should build one deployable artifact once and promote that same artifact through environments, not rebuild per environment.

Quality gates

Required checks—tests, coverage thresholds, static analysis, vulnerability scans—block a merge or deployment until they pass.

Environments and promotion

Separate environments with their own configuration and approval rules let a change move from validation toward production deliberately.

Identity and permissions

Job-scoped tokens, protected environments, and OIDC federation give each stage only the short-lived access it needs.

Release safety and feedback

Progressive delivery, smoke tests, service indicators, concurrency controls, rollback, and delivery metrics close the operational loop.

Reproducibility and caching

Pinned SDKs, lock files, deterministic commands, isolated runners, and correctly keyed caches keep results explainable.

Provenance and audit

Commit identity, artifact digests, SBOMs, attestations, approvals, and deployment records connect source review to production state.

Architecture

A commit triggers a pipeline that restores, builds, and tests the change, then packages and promotes one artifact through environments toward production.

Commit / PR
Build & test
Artifact
Deploy & promote

Conceptual architecture · Adapt to your system context

Implementation walkthrough

The CI/CD Release Pipeline verifies a .NET 10 solution, audits dependencies, publishes one release artifact, preserves commit and digest identity, and promotes that artifact through a protected production environment without rebuilding.

  1. 01
    Define the release contract

    Specify source trigger, version identity, artifact contents, environments, approvals, deployment mechanism, evidence, owner, and rollback.

  2. 02
    Make local commands authoritative

    Ensure the same restore, build, test, publish, audit, and smoke commands work locally and in CI.

  3. 03
    Restore deterministically

    Pin the SDK and tools, commit lock files where appropriate, use locked restore, and key caches from dependency inputs.

  4. 04
    Fail fast in CI

    Run formatting or compilation and fast tests before expensive integration, container, or end-to-end stages.

  5. 05
    Create one artifact

    Publish once after verification, calculate its digest, attach source and version metadata, generate an SBOM, and retain it immutably.

  6. 06
    Promote through environments

    Download the same artifact in deployment jobs and vary configuration, identity, and approval policy rather than rebuilding binaries.

  7. 07
    Secure the workflow

    Minimize token permissions, isolate untrusted pull requests, protect environments, and exchange OIDC identity for short-lived cloud access.

  8. 08
    Observe and improve

    Record deployment status, run smoke checks, automate rollback signals, and measure lead time, frequency, failure rate, and recovery time.

Code example

A focused workflow restores, builds, and tests on every pull request before anything is published.

.github/workflows/ci.yml
name: ci
on:
  pull_request:
  push:
    branches: [main]
jobs:
  build-and-test:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with:
          dotnet-version: '10.0.x'
      - run: dotnet restore
      - run: dotnet build --no-restore -c Release
      - run: dotnet test --no-build -c Release --logger trx

Testing strategy

A pipeline must validate both the product and its own release behavior.

  • Run unit and focused integration tests on every pull request.
  • Exercise workflow changes on a safe branch or disposable environment.
  • Assert artifacts contain expected files and metadata.
  • Verify artifact digests before deployment.
  • Run post-deployment smoke and critical-journey checks.
  • Practice rollback, credential expiry, runner failure, and partial deployment recovery.

Security considerations

Delivery systems are privileged software supply-chain components.

  • Set explicit minimal permissions for every job.
  • Never expose deployment secrets to untrusted fork workflows.
  • Prefer OIDC federation and short-lived credentials over stored cloud keys.
  • Pin dependencies, tools, actions, and reusable workflows to reviewed versions or commits.
  • Scan dependencies, source, containers, and infrastructure definitions.
  • Generate provenance and an SBOM and verify policy before promotion.

Performance and scalability

Fast trusted feedback improves both developer flow and recovery speed.

  • Measure queue time separately from execution time.
  • Cache only reproducible dependencies and invalidate from lock inputs.
  • Parallelize independent test lanes without sharing mutable state.
  • Use change-aware selection carefully and retain a full verification lane.
  • Publish test results immediately when a stage fails.
  • Remove redundant gates after proving they cover the same risk.

Deployment and operations

Release progressively and preserve a clear route back to the last known-good state.

  • Protect production with environment-specific authorization and concurrency control.
  • Deploy the verified artifact by immutable version or digest.
  • Apply database changes with backward-compatible expand-and-contract sequencing.
  • Use rolling, blue-green, or canary exposure based on risk.
  • Gate progression on health and service-level indicators.
  • Record who deployed what, where, when, and with which evidence.

Common problems and fixes

CI passes locally but fails on the runner.

Likely cause: SDK, OS, locale, time, file casing, or hidden dependencies differ.

Fix: Pin the environment, remove machine assumptions, and reproduce using the runner image or container.

Restore uses stale packages.

Likely cause: The cache key does not include lock or project dependency inputs.

Fix: Key caches from dependency files and treat cache as optimization rather than source of truth.

Deployment contains code different from staging.

Likely cause: The pipeline rebuilt separately for each environment.

Fix: Publish once, store immutably, and promote the identical digest.

A secret is printed in logs.

Likely cause: A command echoed credentials or masking was incomplete.

Fix: Rotate it, remove logging, use secret-safe inputs, and prefer federated identity.

Two deployments race.

Likely cause: No environment concurrency policy exists.

Fix: Serialize deployments per environment and define whether newer runs cancel queued or active work.

Rollback restores code but the service remains broken.

Likely cause: Schema or configuration changes were not backward compatible.

Fix: Use expand-and-contract migrations, version configuration, and test full rollback paths.

Best practices

  • Fail fast: run restore, build, and unit tests before anything slow like integration tests or container builds.
  • Build the deployable artifact once and reuse it across every environment instead of rebuilding per stage.
  • Pin tool and action versions so a pipeline behaves the same today and in six months.
  • Keep secrets in the platform's secret store, never in workflow files or environment variables checked into source.
  • Use explicit least-privilege permissions and short-lived federated deployment identity.
  • Automate smoke evidence and preserve a rehearsed rollback path for every production release.

Production checklist

  • SDK, tools, dependencies, and actions are pinned.
  • Restore, build, test, audit, and publish commands are reproducible locally.
  • One immutable artifact is promoted without rebuild.
  • Pipeline permissions and environment identities are least privilege.
  • Untrusted code cannot access protected credentials.
  • Artifact digest, provenance, SBOM, and source commit are traceable.
  • Deployment health, concurrency, approval, and rollback are automated.
  • Delivery speed, failure rate, and recovery time are measured.

Common interview questions

What is the difference between continuous delivery and continuous deployment?

Continuous delivery means every change is automatically verified and ready to release, with a manual approval to actually deploy; continuous deployment removes that manual gate and ships automatically once checks pass.

Why build one artifact and promote it, instead of rebuilding for each environment?

Rebuilding per environment risks shipping code that differs from what was tested—different dependency versions, timestamps, or compiler output—so promoting one immutable artifact keeps what you tested and what you ship identical.

How should a pipeline handle a failing quality gate?

It should block the merge or deployment, report the specific failure clearly, and leave the previous known-good artifact in place rather than partially deploying a change.

Why prefer OIDC over a stored cloud credential?

OIDC exchanges trusted workflow identity for short-lived scoped access, avoiding a long-lived secret that can leak, be copied, or outlive its intended job.

How do database changes affect rollback?

A binary rollback can fail after a breaking schema migration, so use backward-compatible expand-and-contract changes and verify old and new versions during transition.

What is the purpose of a deployment environment?

It scopes configuration, protection rules, identity, concurrency, approvals, and audit history for a target such as staging or production.

Which delivery metrics are most useful?

Lead time, deployment frequency, change failure rate, and recovery time reveal both flow and stability when interpreted with product and reliability context.

Dedicated GitHub sample

Clone, run, test, and modify the focused implementation created for this guide.

Verified sample

CI/CD Release Pipeline

A .NET 10 release metadata tool and GitHub Actions workflow demonstrating deterministic verification, dependency auditing, immutable artifacts, protected promotion, and OIDC-ready permissions.

.NET 10GitHub ActionsCI/CDxUnit
dedicated-samplebuild-onceartifact-promotionsupply-chain
Run
dotnet run --project src/ReleaseManifest
Test
dotnet test CicdReleasePipeline.slnx