$npx -y skills add wshaddix/dotnet-skills --skill dotnet-ado-publishPublishing .NET artifacts from Azure DevOps. NuGet push, containers to ACR, pipeline artifacts.
| 1 | # dotnet-ado-publish |
| 2 | |
| 3 | Publishing pipelines for .NET projects in Azure DevOps: NuGet package push to Azure Artifacts and nuget.org, container image build and push to Azure Container Registry (ACR) using `Docker@2`, artifact staging with `PublishBuildArtifacts@1` and `PublishPipelineArtifact@1`, and pipeline artifacts for multi-stage release pipelines. |
| 4 | |
| 5 | **Version assumptions:** `DotNetCoreCLI@2` for pack/push operations. `Docker@2` for container image builds. `NuGetCommand@2` for NuGet push to external feeds. `PublishPipelineArtifact@1` (preferred over `PublishBuildArtifacts@1`). |
| 6 | |
| 7 | **Scope boundary:** This skill owns artifact publishing pipelines from Azure DevOps. Container image authoring (Dockerfile best practices, SDK container properties) is owned by [skill:dotnet-containers]. Native AOT compilation configuration is owned by [skill:dotnet-native-aot] -- this skill references AOT for CI pipeline configuration only. CLI-specific release pipelines are owned by [skill:dotnet-cli-release-pipeline]. Starter CI templates are owned by [skill:dotnet-add-ci]. |
| 8 | |
| 9 | **Out of scope:** Container image authoring (Dockerfile, base image selection) -- see [skill:dotnet-containers]. Native AOT MSBuild configuration -- see [skill:dotnet-native-aot]. CLI release pipelines -- see [skill:dotnet-cli-release-pipeline]. Starter CI templates -- see [skill:dotnet-add-ci]. GitHub Actions publishing -- see [skill:dotnet-gha-publish]. ADO-unique features (environments, service connections) -- see [skill:dotnet-ado-unique]. |
| 10 | |
| 11 | Cross-references: [skill:dotnet-containers] for container image authoring and SDK container properties, [skill:dotnet-native-aot] for AOT publish configuration in CI, [skill:dotnet-cli-release-pipeline] for CLI-specific release automation, [skill:dotnet-add-ci] for starter publish templates. |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## NuGet Push to Azure Artifacts |
| 16 | |
| 17 | ### Push with `DotNetCoreCLI@2` |
| 18 | |
| 19 | ```yaml |
| 20 | trigger: |
| 21 | tags: |
| 22 | include: |
| 23 | - 'v*' |
| 24 | |
| 25 | stages: |
| 26 | - stage: Pack |
| 27 | jobs: |
| 28 | - job: PackJob |
| 29 | pool: |
| 30 | vmImage: 'ubuntu-latest' |
| 31 | steps: |
| 32 | - task: UseDotNet@2 |
| 33 | inputs: |
| 34 | packageType: 'sdk' |
| 35 | version: '8.0.x' |
| 36 | |
| 37 | - task: DotNetCoreCLI@2 |
| 38 | displayName: 'Pack' |
| 39 | inputs: |
| 40 | command: 'pack' |
| 41 | packagesToPack: 'src/**/*.csproj' |
| 42 | configuration: 'Release' |
| 43 | outputDir: '$(Build.ArtifactStagingDirectory)/nupkgs' |
| 44 | versioningScheme: 'byEnvVar' |
| 45 | versionEnvVar: 'PACKAGE_VERSION' |
| 46 | env: |
| 47 | PACKAGE_VERSION: $(Build.SourceBranchName) |
| 48 | |
| 49 | - task: PublishPipelineArtifact@1 |
| 50 | displayName: 'Upload NuGet packages' |
| 51 | inputs: |
| 52 | targetPath: '$(Build.ArtifactStagingDirectory)/nupkgs' |
| 53 | artifactName: 'nupkgs' |
| 54 | |
| 55 | - stage: PushToFeed |
| 56 | dependsOn: Pack |
| 57 | jobs: |
| 58 | - job: PushJob |
| 59 | pool: |
| 60 | vmImage: 'ubuntu-latest' |
| 61 | steps: |
| 62 | - download: current |
| 63 | artifact: nupkgs |
| 64 | |
| 65 | - task: NuGetAuthenticate@1 |
| 66 | displayName: 'Authenticate NuGet' |
| 67 | |
| 68 | - task: DotNetCoreCLI@2 |
| 69 | displayName: 'Push to Azure Artifacts' |
| 70 | inputs: |
| 71 | command: 'push' |
| 72 | packagesToPush: '$(Pipeline.Workspace)/nupkgs/*.nupkg' |
| 73 | nuGetFeedType: 'internal' |
| 74 | publishVstsFeed: 'MyProject/MyFeed' |
| 75 | ``` |
| 76 | |
| 77 | ### Version from Git Tag |
| 78 | |
| 79 | Extract the version from the triggering Git tag using a script step. `Build.SourceBranch` is a runtime variable, so use a script to parse it rather than compile-time template expressions: |
| 80 | |
| 81 | ```yaml |
| 82 | steps: |
| 83 | - script: | |
| 84 | set -euo pipefail |
| 85 | if [[ "$(Build.SourceBranch)" == refs/tags/v* ]]; then |
| 86 | VERSION="${BUILD_SOURCEBRANCH#refs/tags/v}" |
| 87 | else |
| 88 | VERSION="0.0.0-ci.$(Build.BuildId)" |
| 89 | fi |
| 90 | echo "##vso[task.setvariable variable=packageVersion]$VERSION" |
| 91 | displayName: 'Extract version from tag' |
| 92 | |
| 93 | - task: DotNetCoreCLI@2 |
| 94 | displayName: 'Pack' |
| 95 | inputs: |
| 96 | command: 'pack' |
| 97 | packagesToPack: 'src/**/*.csproj' |
| 98 | configuration: 'Release' |
| 99 | outputDir: '$(Build.ArtifactStagingDirectory)/nupkgs' |
| 100 | arguments: '-p:Version=$(packageVersion)' |
| 101 | ``` |
| 102 | |
| 103 | --- |
| 104 | |
| 105 | ## NuGet Push to nuget.org |
| 106 | |
| 107 | ### Push with `NuGetCommand@2` |
| 108 | |
| 109 | For pushing to external NuGet feeds (nuget.org), use a service connection: |
| 110 | |
| 111 | ```yaml |
| 112 | - task: NuGetCommand@2 |
| 113 | displayName: 'Push to nuget.org' |
| 114 | inputs: |
| 115 | command: 'push' |
| 116 | packagesToPush: '$(Pipeline.Workspace)/nupkgs/*.nupkg' |
| 117 | nuGetFeedType: 'external' |
| 118 | publishFeedCredentials: 'NuGetOrgServiceConnection' |
| 119 | ``` |
| 120 | |
| 121 | The service connection stores the nuget.org API key securely. Create it in Project Settings > Service Connections > NuGet. |
| 122 | |
| 123 | ### Conditional Push (Stable vs Pre-Release) |
| 124 | |
| 125 | ```yaml |
| 126 | - task: NuGetCommand@2 |
| 127 | displayName: 'Push to nuget.org |