Overview
Continuous Integration (CI) and Continuous Deployment (CD) are essential for delivering high‑quality .NET applications. This tutorial walks you through setting up a CI pipeline that runs automated tests and a CD pipeline that safely deploys your app.
Prerequisites
- .NET SDK 8.0 or later
- Git repository (GitHub, Azure Repos, or GitLab)
- Access to Azure DevOps, GitHub Actions, or GitLab CI
- Docker (optional, for containerized testing)
Step‑by‑Step Guide
Azure DevOps
GitHub Actions
GitLab CI
Azure DevOps Pipeline
Create a azure-pipelines.yml at the root of your repo:
# azure-pipelines.yml
trigger:
- main
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.x'
- script: dotnet restore
displayName: 'Restore NuGet packages'
- script: dotnet build --configuration $(buildConfiguration) --no-restore
displayName: 'Build'
- script: dotnet test --configuration $(buildConfiguration) --no-build --logger trx
displayName: 'Run Tests'
- task: PublishTestResults@2
inputs:
testResultsFiles: '**/*.trx'
testRunTitle: 'Unit Tests'
Best Practices
- Fail the pipeline on any test failure.
- Run tests in parallel when possible.
- Separate unit, integration, and UI tests into distinct jobs.
- Cache NuGet packages to speed up builds.
- Use environment variables or secret stores for credentials.