Skip to main content
Containerizing your self-hosted Azure Pipelines agent on Windows provides:
  • Scalability: Scale agents up or down on demand
  • Consistency: Bundle all dependencies to avoid “works on my machine” issues
  • Isolation: Keep each build environment separate
  • Portability: Move containers across hosts with minimal effort
In this guide, you’ll build a basic Windows container agent, then enhance it with the .NET SDK and Visual Studio Build Tools for ASP.NET Core builds.

Prerequisites

  • Docker Desktop for Windows (install guide)
  • Docker switched to Windows containers (Docker icon → Switch to Windows containers)
  • Azure DevOps organization, project, and a Personal Access Token (PAT)

1. Create a Basic Container Agent

1.1 Initialize Folder & Dockerfile

Open PowerShell:
Create azpagentwindows.dockerfile:
Dockerfile Save As dialog in code editor with filename "azpagentwindows.dockerfile"

1.2 Add the start.ps1 Script

Place this next to your Dockerfile. It downloads, configures, and runs the agent:
For better security, mount your PAT via AZP_TOKEN_FILE instead of passing it directly.

1.3 Build and Run the Container

You should see startup logs:

2. Verify the Agent in Azure DevOps

Navigate to Project settingsAgent poolsDefaultAgents. Confirm Docker Agent - Windows is listed.

3. Test with a Simple Pipeline

Create azure-pipelines.yml:
Push to your repo, grant permissions, and verify the container agent executes the job.

4. Limitation: .NET Builds on Server Core

A plain Server Core image shows queued .NET pipelines:
Azure DevOps pipeline titled "Set up CI with Azure Pipelines" queued
The Server Core base lacks MSBuild, .NET SDK, and build tools. It reports zero capabilities and cannot pick up .NET jobs.

5. Enhance the Image with .NET SDK & Build Tools

Switch to the .NET SDK image and install Visual Studio Build Tools:
Rebuild and redeploy:
Look for Scanning for tool capabilities in the logs to confirm MSBuild and .NET SDK detection.

6. Build an ASP.NET Core Application

Use this pipeline to restore, build, and test an ASP.NET Core solution:
Your enhanced container agent will now restore packages, compile the solution, and run tests just like a full self-hosted agent.

Base Image Comparison


Conclusion

Containerized Windows agents deliver portability, consistency, and scalability for Azure DevOps pipelines. By basing your image on the .NET SDK, adding Visual Studio Build Tools, and updating PATH, you unlock MSBuild and SDK capabilities for seamless ASP.NET Core builds.

Watch Video