DEV Community

Kohei Kawata
Kohei Kawata

Posted on

Azure Pipelines predefined variables and directory structure


In this article, I would like to share my learnings about the directory structure of Azure pipeline Microsoft-hosted agents. This code sample includes the ready-to-use Azure pipelines with windows-2019 and windows-2022.


Predefined variables

Azure Pipelines have predefined variables which you can use on your pipelines. There are different directory variables, some of which overlap, some of them are under a different partition. I am trying to describe those predefined variables below.

windows-2019 (Microsoft-hosted agent)

Image description

  • Agent.ToolsDirectory or Agent.TempDirectory are used for different versions of tools. Agent.ToolsDirectory is under C: and then tools are cached and not cleaned up across the pipeline runs. Agent.TempDirectory is under D: and then cleaned up after a pipeline run. The code example below lets the pipeline use the cached versions of .NET 6 tools.
- task: UseDotNet@2
  displayName: Use .NET 6 sdk
    packageType: sdk
    version: 6.0.x
    installationPath: $(Agent.ToolsDirectory)/dotnet
Enter fullscreen mode Exit fullscreen mode
  • Agent.BuildDirectory and Pipeline.Workspace are at D:\a\1which is a workspace directory for a particular pipeline.
  • Build.StagingDirectory and Build.ArtifactStagingDirectory are at D:\a\1\a, which is used for where build artifacts are copied before being pushed.
  • Build.BinariesDirectory is at D:\a\1\b, which is used for compiled binaries.
  • Build.SourcesDirectory and System.DefaultWorkingDirectory are at D:\a\1\a, which are used for your source code files.

.NET Restore, Build, Publish

dotnet restore

dotnet restore creates obj folder and includes some of files regarding Nuget packages.

Image description

dotnet build

dotnet build outputs dll files and exe files under bin and obj.

Image description

dotnet publish

dotnet publish outputs dll files and exe files under a pointed folder. For example, the code example outputs files under publish folder and then those files are zipped. In this case, the project name is TravelApi and the zip file name is, which is used for Azure App Service deployment. The difference from dotnet build is includes web.config in addition to the build files.

Image description

Top comments (0)