DEV Community

jcarloscandela
jcarloscandela

Posted on

🚀 Speed Up Your CI/CD Pipelines in .NET with two tweaks

Hey devs! 👋

If your CI/CD pipelines sometimes feel a bit sluggish—especially in .NET projects—you're not alone. I recently noticed that some of our Azure DevOps pipelines were taking longer than they should, so I explored a few ways to optimize them.

It turns out, just two small tweaks in your YAML file can make a big difference. Here they are:

steps:
- checkout: self
  clean: true
  fetchDepth: 1
  fetchTags: false

- task: Cache@2
  displayName: 'Cache NuGet packages'
  inputs:
    key: 'nuget | "$(Agent.OS)" | **/packages.lock.json,**/*.csproj'
    restoreKeys: |
      nuget | "$(Agent.OS)"
    path: $(UserProfile)\.nuget\packages
Enter fullscreen mode Exit fullscreen mode

✅ What these steps do

1. Optimized checkout

By default, Azure DevOps will retrieve all branches and tags from the repository during checkout—even ones you don't need for the current run. In large repositories with a long history, this can slow things down significantly.

By adding:

  fetchDepth: 1
  fetchTags: false
Enter fullscreen mode Exit fullscreen mode

...you ensure that only the latest commit from the current branch is downloaded. Combined with:

  clean: true
Enter fullscreen mode Exit fullscreen mode

...you also get a fresh workspace, which helps avoid conflicts or leftover files from previous runs.

🚀 Result: Faster checkouts, especially in repos with a lot of branches or tags.


2. NuGet Package Caching

This step sets up caching for your NuGet packages:

  path: $(UserProfile)\.nuget\packages
Enter fullscreen mode Exit fullscreen mode

It prevents the pipeline from redownloading the same packages on every run. Instead, it restores from cache unless something has changed (like your packages.lock.json or .csproj files).

🚀 Result: Faster restores and less network overhead.

🔔 Note: This cache is specific to NuGet. If you're using other package managers like npm or yarn, you'll need different keys and paths.


🧹 Bonus Tip: Clean Up Old Branches & Tags

One overlooked cause of slow checkouts is the number of branches and tags in the repo. If your repository still contains feature branches or tags from a year (or more) ago, consider cleaning them up.

Removing old references helps Git operations run faster and keeps your repository healthier overall.


📈 Results

After applying these tweaks, our pipeline durations improved noticeably—especially during the checkout and restore phases.

If you're working with .NET projects and Azure DevOps pipelines, this is a low-effort, high-impact improvement you can make today.


💬 Have you optimized your pipelines in other ways? Share your tips in the comments—I'd love to hear what worked for you!

Top comments (0)