π Azure Pipelines Documentation
Table of Contents
- π Overview & Purpose
- π― Key Functional Areas
- βοΈ Dependencies & Technologies
- π¦ Pipeline Variables (Data Models)
- π§ 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 - π οΈ Error Handling & Return Types
- π ThirdβParty Integrations
- π Pipeline Flow Diagram (Mermaid UML)
- π Sample Usage & Customization
- β API Endpoints Overview
- β 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
VSBuildtask - 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.xto6.xor7.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.zipoutput./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
0on success. - On failure, snapshot logs can be downloaded for diagnostics.
- Each task returns
-
Retry Logic:
- Can be configured globally under
retryCountOnTaskFailureif needed.
- Can be configured globally under
π 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
-
Change Target Branch
trigger: - develop - feature/* -
Add Code Analysis (SonarQube)
- task: SonarCloudPrepare@1 inputs: ... - task: SonarCloudAnalyze@1 - task: SonarCloudPublish@1 -
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! π