C# and .NET Pipeline
Learn how to structure enterprise-grade CI pipelines for modern .NET applications using the cross-platform .NET CLI, managing dependencies, compiling binaries, and logging test outcomes.
What is a C# and .NET Pipeline?
With the shift from legacy Windows-only frameworks to modern, cross-platform **.NET (Core)** ecosystems, running C# compilation tasks inside Jenkins has become highly versatile. Continuous Integration workflows for .NET apps focus on consolidating NuGet dependency tracking, verifying type-safety constraints, executing unit tests, and compiling optimized static distribution binaries.
Using the unified dotnet Command Line Interface (CLI), your Jenkins automation scripts can build and test systems seamlessly across either Linux build agents or Windows server execution nodes. This uniformity ensures that environmental code disparities are detected early during pull request reviews before pushing production assemblies into cloud runtimes.
Key Concepts
NuGet Dependency Restore
Invoking explicit package recovery steps via dotnet restore to download and cache external dependencies mapped inside .csproj manifests.
The VSTest Engine Logging
Instructing execution frameworks to format test summaries using specific flags like --logger "trx" or custom JUnit adaptors so Jenkins can chart error histories.
Release Configuration Profiles
Compiling assets under strict production parameters (-c Release) to enforce optimizations, prune debug symbols, and improve application velocity.
Self-Contained Publishing
Using dotnet publish configurations to output a consolidated binary framework distribution containing everything the system needs to run on target infrastructure.
Practical Jenkins Example
This cross-platform declarative pipeline restores dependencies, builds the target solution under a Release configuration, runs tests with custom test loggers, and archives the output assemblies:
pipeline {
agent any
stages {
stage('Restore Dependencies') {
steps {
echo 'Fetching NuGet package libraries...'
// Resolves external package dependencies pinned inside solution maps
sh 'dotnet restore'
}
}
stage('Compile Solution') {
steps {
echo 'Compiling C# application binaries...'
// Builds structural elements without re-running restore overheads
sh 'dotnet build --configuration Release --no-restore'
}
}
stage('Execute Unit Tests') {
steps {
echo 'Running test assertions...'
// Outputs a visual Studio Test Results (.trx) file for dashboard processing
sh 'dotnet test --configuration Release --no-build --logger "trx"'
}
}
stage('Publish Distribution Bundle') {
steps {
echo 'Assembling standalone target files...'
sh 'dotnet publish --configuration Release --no-build --output ./publish'
}
}
}
post {
always {
echo 'Parsing test suite execution outcomes...'
// Ingests generated TRX logs via the MSTest/VSTest plugin engine block
mstest testResults: '**/*.trx', keepLongStdio: true
}
success {
echo 'Build successful. Archiving compiled artifacts...'
// Persists the self-contained output directory structure onto the controller
archiveArtifacts artifacts: 'publish/**', fingerprint: true, allowEmptyArchive: false
}
}
}
Practice Exercise
- Verify that the target Jenkins agent execution machine has the official .NET SDK runtime libraries installed globally.
- Ensure that the **MSTest Plugin** is installed on your Jenkins controller via **Manage Jenkins → Plugins** to process TRX files.
- Create a new **Pipeline** automation build workspace in your console portal directory named
dotnet-ci-pipeline. - Paste the complete cross-platform declarative structure script template listed in the practical configuration example above.
- Trigger a build run, evaluate the **Console Output**, and open the **Test Result** tab to audit individual method assertion trends.
Summary
You have completed the C# and .NET Pipeline lesson. Concluding your training on native language runtimes sets up a natural progression toward infrastructure orchestration, starting with **Cloud-Native Jenkins** structures.