Skip to content

Custom Azure Pipeline Optimization Script. Ready-to-use MSBuild-based solution. Easily integrate to streamline builds, especially useful for projects without a fully automated CI/CD setup.

License

Notifications You must be signed in to change notification settings

damianczer/Azure-DevOps-Custom-CI-Pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 

Repository files navigation

Azure DevOps Custom CI Pipeline (Time Boost)

⚡ Intelligent Build Optimization for Legacy .NET Solutions

GitHub stars GitHub watchers GitHub issues License: MIT

Build only what changed, not the entire solution!

FeaturesProblemSolutionSetupDocumentation

🎯 Overview

This PowerShell script revolutionizes CI/CD pipelines for large .NET solutions by implementing intelligent selective building. Instead of rebuilding hundreds of projects for a single file change, it analyzes Git diff and builds only affected projects.

Perfect for:

  • 🏢 Enterprise legacy applications with 100+ projects
  • 🔧 Teams without Docker or modern containerization
  • Projects with 20+ minute build times
  • 💰 Organizations with limited CI/CD budget

😫 The Problem

Does this sound familiar?

❌ Solution with 150+ projects
❌ Every PR triggers a full solution build
❌ 20-30 minutes waiting for a single line change
❌ Legacy codebase without Docker support
❌ No budget for proper CI/CD refactoring

Traditional MSBuild approach:

<MSBuild Projects="EntireSolution.sln" />

☝️ Rebuilds EVERYTHING, even if you changed one CSS file!

✅ The Solution

Smart Selective Building

graph LR
    A[Feature Branch] -->|Git Diff| B[Changed Files]
    B --> C[Extract Projects]
    C --> D[Build Only Changed]
    D --> E[20 min saved! ⚡]
Loading

Our approach:

<MSBuild Projects="$(projects)" />

☝️ Builds only changed projects + their dependencies!

🌟 Key Features

Feature Description
🎯 Selective Building Analyzes Git changes and builds only affected projects
🔍 Dependency Tracking Automatically includes referenced projects
🌿 Branch Comparison Compares feature branches against master/develop
🔄 PR Support Native Azure DevOps Pull Request integration
📊 Frontend Detection Separate tracking for frontend changes
⚙️ Customizable Adapt to your project structure
📈 Pipeline Variables Sets Azure DevOps variables for next steps

🛠️ Technology Stack

Technology Purpose Documentation
PowerShell Script Engine Learn More
MSBuild Build System Learn More
Azure DevOps CI/CD Platform Learn More
Git Version Control Learn More

📊 Performance Comparison

Before vs After

❌ Before (Traditional Build)

Before

Full solution build

  • ⏱️ ~25 minutes
  • 🔨 150 projects rebuilt
  • 💸 High Azure costs

✅ After (Selective Build)

After

Only changed projects

  • ~5 minutes
  • 🎯 3-5 projects rebuilt
  • 💰 80% cost reduction

🎉 Result: ~20 minutes saved per build!

🚀 Quick Start

Prerequisites

# Required
- Azure DevOps account
- Git repository
- MSBuild installed
- PowerShell 5.1+

Installation

  1. Clone the repository

    git clone https://github.com/damianczer/azure-devops-msbuild-auto.git
  2. Add script to your pipeline

    steps:
    - task: PowerShell@2
      inputs:
        filePath: 'script.ps1'
        arguments: >
          -CompareSourceBranch "master"
          -BranchName "$(Build.SourceBranch)"
          -Repository "$(Build.SourcesDirectory)"
          -TargetBranch "$(System.PullRequest.TargetBranch)"
  3. Configure MSBuild task

    - task: MSBuild@1
      condition: eq(variables['isBuildable'], 'True')
      inputs:
        solution: '$(projects)'

⚙️ Configuration Guide

Step 1: PowerShell Task Configuration

Step Configuration

Parameters:

  • CompareSourceBranch: Base branch (e.g., master, develop)
  • BranchName: Current branch from pipeline variable
  • Repository: Source directory path
  • TargetBranch: PR target branch (for PR builds)

Step 2: Pipeline Variables

Pipeline Variables

Output Variables:

  • projects: Space-separated list of .csproj files
  • hasFrontendChanged: Boolean flag for frontend changes
  • isBuildable: Boolean flag if build is needed

Step 3: MSBuild Configuration

MSBuild Configuration

Build.proj Example:

<Project>
  <Target Name="BuildChanged">
    <MSBuild Projects="$(projects)" 
             Properties="Configuration=Release;Platform=Any CPU" 
             BuildInParallel="true" />
  </Target>
</Project>

🔍 How It Works

# 1️⃣ Compare branches
git diff --name-only feature-branch..master

# 2️⃣ Extract changed files
src/Feature/Authentication/code/Models/User.cs
src/Feature/Catalog/code/Services/ProductService.cs
src/Frontend/App/components/Header.tsx

# 3️⃣ Find related .csproj files
src/Feature/Authentication/Authentication.csproj
src/Feature/Catalog/Catalog.csproj

# 4️⃣ Set pipeline variables
projects = "Auth.csproj Catalog.csproj"
hasFrontendChanged = true
isBuildable = true

# 5️⃣ MSBuild uses variables
<MSBuild Projects="$(projects)" />

🎨 Customization

Adapt to Your Project Structure

The script looks for /code directory by default. Modify for your structure:

# Current structure: src/Feature/FeatureName/code/
if ($element.Contains("/code")) {
    # Extract project path
}

# Your structure: src/Modules/ModuleName/
if ($element.Contains("/Modules/")) {
    $index = $element.IndexOf("/Modules/")
    # Custom logic
}

Add Custom Patterns

# Track database changes
if ($element.Contains("/Database/")) {
    $hasDatabaseChanged = $true
}

# Track API changes
if ($element.Contains("/API/")) {
    $hasAPIChanged = $true
}

📚 Documentation

Script Parameters

Parameter Required Description Example
CompareSourceBranch Branch to compare against master, develop
BranchName Current branch name feature/new-feature
Repository Repository path C:\Repos\MyProject
TargetBranch PR target branch refs/heads/develop

Output Variables

variables:
  projects: 'Project1.csproj Project2.csproj'
  hasFrontendChanged: 'true'
  isBuildable: 'true'

🤝 Contributing

Contributions are welcome! Here's how:

  1. 🍴 Fork the repository
  2. 🌿 Create feature branch (git checkout -b feature/AmazingFeature)
  3. 💾 Commit changes (git commit -m 'Add AmazingFeature')
  4. 📤 Push to branch (git push origin feature/AmazingFeature)
  5. 🔀 Open Pull Request

📄 License

This project is licensed under the MIT License - see the LICENSE file for details.

MIT License - Copyright (c) 2025 Damian Czerwiński

👨‍💻 Author

Damian Czerwiński

If this project helped you, please ⭐ star this repository!

💡 Questions or Issues?

Open an IssueDiscussions

Made with ❤️ for the .NET Community

About

Custom Azure Pipeline Optimization Script. Ready-to-use MSBuild-based solution. Easily integrate to streamline builds, especially useful for projects without a fully automated CI/CD setup.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published