Table of Contents
- Table of Contents
- trigger, pool, variables
- DotNetCoreCLI@2
- Publish Artifacts
- PowerShell@2
- Troubleshooting
This is for creating a pipeline using YAML in Azure DevOps, specifically. I'm assuming you've gotten to the point where you have a blank or template YAML file for your pipeline.
trigger, pool, variables
trigger:
- master
pool:
name: Default
demands:
- Agent.OS -equals Windows_NT
variables:
solution: '**/*.sln'
buildPlatform: 'Any CPU'
buildConfiguration: 'Release'
buildRuntime: 'win-x64'
buildFramework: 'net10.0-windows10.0.19041.0'
system.debug: 'true'
# setting system.debug to true will let you see more output info
Trigger - specifies which branch will cause the pipeline to run
pool - a pool contains a collection of agents, each agent is a piece of software running on a machine, virtual or otherwise (this is set up for my at my company, though setting this up is probably an article of its own)
variables - don't overthink this; it's literally just variables. These will get used later
DotNetCoreCLI@2
- task: DotNetCoreCLI@2
displayName: 'Publish Example Project'
inputs:
command: publish
projects: '*/Example_Project_Name.csproj'
publishWebProjects: false
arguments: '--configuration $(buildConfiguration)
--runtime $(buildRuntime)
--framework $(buildFramework)
--self-contained
--output $(Build.ArtifactStagingDirectory)'
zipAfterPublish: true
According to Microsoft, DotNetCoreCLI@2 is used to: "Build, test, package, or publish a .NET application, or run a custom .NET CLI command."
The @2 is the version number for this command. It used to be @1 and may change to @3 at some point.
There are quite a few options to put under this:
command | projects | custom | arguments | restoreArguments | zipAfterPublish | publishTestResults | nuGetFeedType | configuration | requestTimeout | publishWebProjects | modifyOutputPath
command
Options for command include:
build | push | pack | publish | restore | run | test | custom
projects
According to Microsoft:
projects - Path to project(s) or solution(s)
string. Optional. Use when command = build || command = restore || command = run || command = test || command = custom || publishWebProjects = false.The path to the .csproj or .sln file(s) to use. You can use wildcards (e.g. **/*.csproj for all .csproj files in all subfolders). For more information, see the file matching patterns reference.
If there are multiple projects in the solution, put "**/placeholder_text.csproj", otherwise put "*/placeholder_text.csproj". I think, not 100% sure here.
This path is relative to the root of the repository regardless of the workingDirectory setting.
By default, workingDirectory is $(System.DefaultWorkingDirectory)
zipAfterPublish
Set this to true, unless you have another dedicated way you would like to publish this.
Publish Artifacts aka Spit Out The Files You Want
There are two arguments involved with publishing the artifacts:
- The "publish" command
- Will build and publish the project
- The "output" argument tells the command where to place the files
- The "PublishBuildArtifacts" task
- Will pick up and spit out the specified files onto the "Build Artifacts" area (where you can download them!)
- The "pathToPublish" input tells the task where to pick up the files
Both the "output" argument and the "pathToPublish" should be based on the "$(Build.ArtifactStagingDirectory).
To figure out where the build/publish command is placing files, check:
- The "output" argument for the build/publish command
- The command line output for the build/publish step on the DevOps page
AbbottLabsControllerTester -> C:\agent_filepath_goes_here\s\...
AbbottLabsControllerTester -> C:\agent_filepath_goes_here\a\output_argument_will_be_here
The location for the ArtifactStagingDirectory is
C:\agent_filepath_goes_here\a
Step 1: Publish Output
- task: DotNetCoreCLI@2
displayName: 'Publish project'
inputs:
command: 'publish'
projects: '$(project)'
publishWebProjects: false
arguments: '--configuration $(buildConfiguration)
--runtime $(buildRuntime)
--self-contained
--output $(Build.ArtifactStagingDirectory)\Example_Project_V$(Build.BuildNumber)
--framework $(buildFramework)'
zipAfterPublish: true
modifyOutputPath: false
I recommend setting "modifyOutputPath" to false. If "modifyOutputPath" is set to true, the .zip folder will have the same name as the project name.
If modifyOutputPath: true
AbbottLabsControllerTester -> ...\a\Abbott_Labs_Tester_V20260324.26\AbbottLabsControllerTester\
- ExampleProject Published Files
- Example_Project_V20260324.30
- ExampleProjectName.zip
- Project files
If modifyOutputPath: false
AbbottLabsControllerTester -> ...\a\Abbott_Labs_Tester_V20260324.32\
- ExampleProject Published Files
- Example_Project_V20260324.30
- Example_Project_V20260324.30.zip
- Project files
Step 2: PublishBuildArtifacts@1
It's not enough to just publish/create the outputs, you need to tell the pipeline to spit them out for you to download.
task: PublishBuildArtifacts@1
inputs:
pathToPublish: '$(Build.ArtifactStagingDirectory)'
artifactName: 'ExampleProject Published Files'
Important notes:
-
pathToPublish tells the pipeline where to look for the files
- if there's nothing there it will throw a warning and there will be no artifacts
- Both the "pathToPublish" and "artifactName" are required.
- Note! Don't forget the "." in Build.ArtifactStagingDirectory!
Settings UI
You can also add tasks through the UI on DevOps.
If you click on the little gray "settings" text above yaml commands it will show you the settings for said command.

PowerShell@2
I'm not worrying about this for my project but I figured I'd write it down at least.
- task: PowerShell@2
displayName: 'Build Setup'
inputs:
targetType: 'filePath'
filePath: '$(Build.Repository.LocalPath)\DTC Software\AW_DTC\buildSetup.ps1'
arguments: '-publishDirPath "$(Build.ArtifactStagingDirectory)\PLACEHOLDER_TEXT"
-publishZipPath "$(Build.ArtifactStagingDirectory)\Zip"
-publishSetupPath "$(Build.ArtifactStagingDirectory)\Setup"
-nsiFilePath "$(Build.Repository.LocalPath)\DTC Software\AW_DTC\AW_DTC.nsi"'
workingDirectory: '$(Build.ArtifactStagingDirectory)'
The parameters such as publishZipPath are custom to the powershell file.
Troubleshooting
Can't create two projects at a time
Under your publish step, make sure the filepath to your .csproj file is correct.
Not found PathToPublish
The PublishBuildArtifacts has a "pathToPublish" input that tells PublishBuildArtifacts where to look. If the path specified in "pathToPublish" does not exist, this will get thrown.

Top comments (0)