πŸ“‹ Azure Pipelines Documentation


Table of Contents

  1. πŸš€ Overview & Purpose
  2. 🎯 Key Functional Areas
  3. βš™οΈ Dependencies & Technologies
  4. πŸ“¦ Pipeline Variables (Data Models)
  5. πŸ”§ Pipeline Steps & Helper Tasks
    5.1. NuGet Tool Installer
    5.2. Use .NET Core SDK
    5.3. Restore NuGet Packages
    5.4. Build the Solution
    5.5. Run Unit Tests
    5.6. Publish Build Artifacts
  6. πŸ› οΈ Error Handling & Return Types
  7. πŸ”— Third‑Party Integrations
  8. πŸ“ˆ Pipeline Flow Diagram (Mermaid UML)
  9. πŸ“š Sample Usage & Customization
  10. ❌ API Endpoints Overview
  11. βœ… Conclusion

πŸš€ Overview & Purpose

This azure-pipelines.yml file defines a CI (Continuous Integration) process for an ASP.NET Core application targeting the full .NET Framework. It automates:

  • Restoring NuGet packages
  • Building the solution in Release configuration
  • Running unit tests
  • Packaging and publishing build artifacts

Use this pipeline to ensure consistent, repeatable builds on Azure DevOps whenever code is pushed to master.


🎯 Key Functional Areas

Area Description
Trigger Defines which branch(es) initiate a build (master).
Pool Specifies the VM image for build agents (windows-latest).
Variables Centralizes solution path, build platform and configuration.
Steps Sequential tasks: install tools, restore packages, build, test, and publish.
Artifacts Produces a ZIP of the web app for deployment.
Extensibility & Customization Easily add steps for code analysis, publishing symbols, or additional environments.

βš™οΈ Dependencies & Technologies

  • Azure DevOps Pipelines
  • .NET Core SDK 9.x
  • NuGet for package management
  • MSBuild via VSBuild task
  • VSTest for running unit tests
  • PublishBuildArtifacts to upload outputs

πŸ“¦ Pipeline Variables (Data Models)

These are key‐value pairs used throughout the pipeline:

Name Default Value Description
solution **/*.sln Glob pattern to locate all .sln files.
buildPlatform Any CPU MSBuild platform (CPU architecture).
buildConfiguration Release MSBuild configuration (Debug/Release).
Agent.ToolsDirectory Provided by Azure DevOps agent Path where tools (SDKs) are installed.
build.artifactStagingDirectory Agent-specific Directory to stage artifacts for publishing.

πŸ”§ Pipeline Steps & Helper Tasks

Below is the full YAML, followed by a breakdown of each step:

# azure-pipelines.yml
trigger:
  - master

pool:
  vmImage: 'windows-latest'

variables:
  solution: '**/*.sln'
  buildPlatform: 'Any CPU'
  buildConfiguration: 'Release'

steps:
  - task: NuGetToolInstaller@1
  - task: UseDotNet@2
    displayName: 'Use .NET Core sdk'
    inputs:
      packageType: sdk
      version: 9.x
      installationPath: $(Agent.ToolsDirectory)/dotnet

  - task: NuGetCommand@2
    inputs:
      restoreSolution: '$(solution)'

  - task: VSBuild@1
    inputs:
      solution: '$(solution)'
      msbuildArgs: >
        /p:DeployOnBuild=true
        /p:WebPublishMethod=Package
        /p:PackageAsSingleFile=true
        /p:SkipInvalidConfigurations=true
        /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip"
        /p:DeployIisAppPath="Default Web Site"
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'

  - task: VSTest@2
    inputs:
      platform: '$(buildPlatform)'
      configuration: '$(buildConfiguration)'

  - task: PublishBuildArtifacts@1

5.1 NuGet Tool Installer

Task: NuGetToolInstaller@1
Purpose: Ensures a compatible version of NuGet is available on the agent.

No inputs required; uses default latest NuGet.

5.2 Use .NET Core SDK

Task: UseDotNet@2
Purpose: Installs and makes available the specified .NET Core SDK.

Input Value
packageType sdk
version 9.x
installationPath $(Agent.ToolsDirectory)/dotnet

⚠️ If you need .NET 6 or .NET 7, change version: 9.x to 6.x or 7.x.

5.3 Restore NuGet Packages

Task: NuGetCommand@2
Purpose: Restores all NuGet packages referenced by the solution(s).

Input Value
restoreSolution $(solution)

5.4 Build the Solution

Task: VSBuild@1
Purpose: Builds and packages the Web App into a single ZIP.

Key MSBuild Arguments:

  • /p:DeployOnBuild=true – Builds a deployable package.
  • /p:WebPublishMethod=Package – Uses WebDeploy packaging.
  • /p:PackageAsSingleFile=true – Single .zip output.
  • /p:DesktopBuildPackageLocation="$(build.artifactStagingDirectory)\WebApp.zip" – Output path.
  • /p:DeployIisAppPath="Default Web Site" – IIS virtual path.

5.5 Run Unit Tests

Task: VSTest@2
Purpose: Discovers and runs tests in the solution.

Input Value
platform $(buildPlatform)
configuration $(buildConfiguration)

5.6 Publish Build Artifacts

Task: PublishBuildArtifacts@1
Purpose: Takes everything in $(Build.ArtifactStagingDirectory) and publishes it to Azure Pipelines. Consumers (e.g., CD pipelines) can download or deploy these artifacts.


πŸ› οΈ Error Handling & Return Types

  • Task Failures:

    • Any non-zero exit code in a task fails the build.
    • Azure DevOps highlights failed steps in red with detailed logs.
  • Return Values:

    • Each task returns 0 on success.
    • On failure, snapshot logs can be downloaded for diagnostics.
  • Retry Logic:

    • Can be configured globally under retryCountOnTaskFailure if needed.

πŸ”— Third‑Party Integrations

Tool / Service Integration Point
Azure DevOps Core CI engine
NuGet.org Package restore
.NET Core SDK Build and CLI tooling
Visual Studio Test Unit test execution

πŸ“ˆ Pipeline Flow Diagram (Mermaid UML)

graph LR
  T(Trigger: master) --> N1[NuGetToolInstaller]
  N1 --> D1[UseDotNet SDK 9.x]
  D1 --> R[NuGet Restore]
  R --> B[VSBuild & Package]
  B --> T2[VSTest]
  T2 --> P[PublishBuildArtifacts]

πŸ“š Sample Usage & Customization

  1. Change Target Branch

    trigger:
      - develop
      - feature/*
    
  2. Add Code Analysis (SonarQube)

    - task: SonarCloudPrepare@1
      inputs:
        ...
    - task: SonarCloudAnalyze@1
    - task: SonarCloudPublish@1
    
  3. Publish to Azure App Service

    - task: AzureWebApp@1
      inputs:
        azureSubscription: 'MyServiceConnection'
        appType: 'webApp'
        appName: 'my-web-app'
        package: '$(Build.ArtifactStagingDirectory)\WebApp.zip'
    

❌ API Endpoints Overview

Not Applicable
This YAML file does not expose or call any HTTP API endpoints directly. It orchestrates build tasks within Azure DevOps.


βœ… Conclusion

This azure-pipelines.yml provides a robust, out‑of‑the‑box CI workflow for ASP.NET Core (.NET Framework) projects. By automating restore, build, test, and artifact publishing, it ensures:

  • πŸ”„ Consistent builds on every commit
  • βœ”οΈ Early detection of compilation or test failures
  • πŸ“¦ Ready-to-deploy packages

Feel free to extend it with additional tasks (code analysis, deployment steps, notifications) to suit your team’s DevOps practices. Happy building! πŸš€