⚙️ CI/CD in .NET — Complete Guide (2025)
๐งฉ 1. What Is CI/CD?
๐งฑ Continuous Integration (CI)
The process of automatically building, testing, and validating your code each time a developer commits changes.
CI ensures:
Code is always in a buildable state
Automated tests run on every push
Teams detect and fix issues early
๐ Continuous Deployment (CD)
Automatically releases your validated code to staging or production environments.
CD ensures:
Faster releases
Consistent, repeatable deployments
Minimal manual intervention
๐ก 2. CI/CD Workflow for .NET
Here’s what a typical CI/CD pipeline looks like:
Developer Commit (GitHub / Azure Repos)
│
▼
[Continuous Integration]
- Restore NuGet Packages
- Build Solution
- Run Unit Tests
- Code Quality Checks
│
▼
[Continuous Deployment]
- Publish Build Artifacts
- Deploy to Azure App Service / Containers / On-Prem
- Run Smoke Tests
- Monitor via Application Insights
๐งฑ 3. Tools for CI/CD in .NET
Category Tools
Source Control Azure Repos, GitHub, GitLab
Build & Release Automation Azure DevOps Pipelines, GitHub Actions, Jenkins
Artifact Management Azure Artifacts, GitHub Packages, NuGet
Deployment Targets Azure App Service, Containers, Kubernetes, IIS
Monitoring Application Insights, Log Analytics
๐งฐ 4. Setting Up CI/CD in Azure DevOps
๐งฉ Step 1: Create a Pipeline
Go to Azure DevOps → Pipelines → New Pipeline
Connect your Git repo (Azure Repos or GitHub)
Choose Starter pipeline or Existing YAML
๐งฉ Step 2: Define CI Pipeline (Build)
azure-pipelines.yml
trigger:
- main
pool:
vmImage: 'windows-latest'
steps:
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '8.0.x'
- script: dotnet restore
displayName: 'Restore dependencies'
- script: dotnet build --configuration Release
displayName: 'Build solution'
- script: dotnet test --no-build --verbosity normal
displayName: 'Run unit tests'
- task: DotNetCoreCLI@2
inputs:
command: 'publish'
publishWebProjects: true
arguments: '--configuration Release --output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
- publish: $(Build.ArtifactStagingDirectory)
artifact: drop
✅ This builds your .NET app and publishes the artifacts ready for deployment.
๐งฉ Step 3: Define CD Pipeline (Release)
Go to Pipelines → Releases → New pipeline
Choose Azure App Service deployment
Link your build artifact
Configure stages (e.g., Staging → Production)
Add Approvals and Gates if required
Azure DevOps will:
Pull the artifact
Deploy to your Azure App Service (or container)
Mark deployment success/failure
๐ง 5. Setting Up CI/CD with GitHub Actions
Example Workflow
.github/workflows/dotnet.yml
name: .NET CI/CD
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- 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
run: dotnet build --configuration Release --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
- name: Publish
run: dotnet publish -c Release -o ./publish
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v3
with:
app-name: 'my-dotnet-app'
publish-profile: ${{ secrets.AZURE_WEBAPP_PUBLISH_PROFILE }}
package: ./publish
✅ This pipeline builds, tests, and deploys to Azure automatically whenever you push to main.
๐ 6. Security Best Practices
Use Secure Variables & Secrets
Store secrets in Azure Key Vault or GitHub Secrets.
Never commit secrets to source control.
Use Service Connections
Use Azure service connections in DevOps to securely deploy apps.
Restrict Deploy Permissions
Add manual approvals for production stages.
Add Code Quality & Security Scans
Integrate SonarQube, Dependabot, or Microsoft Security Code Analysis.
⚙️ 7. CI/CD for Different .NET App Types
App Type Build Tool Deployment Target
ASP.NET Core Web App dotnet build Azure App Service / Containers
Blazor WebAssembly dotnet publish Azure Static Web Apps
API Backend dotnet build Azure App Service / Functions
Worker Services / Background Jobs dotnet build Azure Container Apps / Kubernetes
Desktop / MAUI MSBuild App Center / Store
๐งฉ 8. Testing Integration
Include test stages in your pipeline:
- script: dotnet test --logger trx
- task: PublishTestResults@2
inputs:
testResultsFormat: 'VSTest'
testResultsFiles: '**/*.trx'
You can also add:
Unit Tests
Integration Tests
UI Tests (Playwright/Selenium)
๐ 9. Monitoring & Rollback
Integrate Application Insights for post-deployment monitoring.
Add Health Checks in your .NET app:
app.MapHealthChecks("/health");
Configure auto-rollback in Azure if deployment fails.
๐งญ 10. Example End-to-End Flow
1️⃣ Developer pushes code to GitHub
2️⃣ GitHub Action triggers build/test pipeline
3️⃣ On success, artifacts are published
4️⃣ Deployment job pushes build to Azure App Service
5️⃣ Application Insights monitors live site
6️⃣ Rollback triggered if issues found
๐งฐ 11. CI/CD Best Practices
✅ Keep pipelines modular (separate build/test/deploy stages)
✅ Use YAML pipelines for versioning
✅ Automate testing at multiple stages
✅ Implement branch policies and pull request validation
✅ Always deploy from build artifacts, never directly from source
✅ Monitor post-deployment performance
๐ 12. Recommended Azure DevOps Pipeline Template
Microsoft provides templates for:
.NET Core Web App
ASP.NET + SQL Database
Blazor + API + Azure Hosting
You can start from the Azure DevOps Pipeline Template Gallery
or GitHub Actions .NET templates
.
✅ Summary
Stage Goal Example Tool
CI Build + Test automatically Azure Pipelines / GitHub Actions
CD Deploy automatically Azure Pipelines / WebApps Deploy
Monitor Track performance Application Insights
Secure Protect credentials Azure Key Vault
Rollback Recover from failure Deployment slots
Learn Dot Net Course in Hyderabad
Read More
Using Azure Services for Full Stack .NET Development
Integrating External APIs in Full Stack .NET Applications
Visit Our Quality Thought Institute in Hyderabad
Subscribe by Email
Follow Updates Articles from This Blog via Email
No Comments