$npx -y skills add wshaddix/dotnet-skills --skill dotnet-ado-build-testConfiguring .NET build/test in Azure DevOps. DotNetCoreCLI task, Artifacts, test results.
| 1 | # dotnet-ado-build-test |
| 2 | |
| 3 | .NET build and test pipeline patterns for Azure DevOps: `DotNetCoreCLI@2` task for build, test, and pack operations, NuGet restore with Azure Artifacts feeds using `NuGetAuthenticate@1`, test result publishing with `PublishTestResults@2` for TRX and JUnit formats, code coverage with `PublishCodeCoverageResults@2` for Cobertura and JaCoCo formats, and multi-TFM matrix strategy across net8.0 and net9.0. |
| 4 | |
| 5 | **Version assumptions:** `DotNetCoreCLI@2` task (current). `UseDotNet@2` for SDK installation. `NuGetAuthenticate@1` for Azure Artifacts. `PublishTestResults@2` and `PublishCodeCoverageResults@2` for reporting. |
| 6 | |
| 7 | **Scope boundary:** This skill owns .NET build and test pipeline configuration for Azure DevOps. Starter CI templates (basic build/test/pack) are owned by [skill:dotnet-add-ci]. Composable pipeline patterns (templates, multi-stage, triggers) are in [skill:dotnet-ado-patterns]. Testing strategy guidance (what to test, test architecture, quality gates) is owned by [skill:dotnet-testing-strategy]. Benchmark CI workflows are owned by [skill:dotnet-ci-benchmarking]. |
| 8 | |
| 9 | **Out of scope:** Starter CI templates -- see [skill:dotnet-add-ci]. Test architecture and strategy -- see [skill:dotnet-testing-strategy]. Benchmark regression detection in CI -- see [skill:dotnet-ci-benchmarking]. Publishing and deployment -- see [skill:dotnet-ado-publish] and [skill:dotnet-ado-unique]. GitHub Actions build/test workflows -- see [skill:dotnet-gha-build-test]. |
| 10 | |
| 11 | Cross-references: [skill:dotnet-add-ci] for starter build/test templates, [skill:dotnet-testing-strategy] for test architecture guidance, [skill:dotnet-ci-benchmarking] for benchmark CI integration. |
| 12 | |
| 13 | --- |
| 14 | |
| 15 | ## `DotNetCoreCLI@2` Task |
| 16 | |
| 17 | ### Build |
| 18 | |
| 19 | ```yaml |
| 20 | steps: |
| 21 | - task: UseDotNet@2 |
| 22 | displayName: 'Install .NET SDK' |
| 23 | inputs: |
| 24 | packageType: 'sdk' |
| 25 | version: '8.0.x' |
| 26 | |
| 27 | - task: DotNetCoreCLI@2 |
| 28 | displayName: 'Restore' |
| 29 | inputs: |
| 30 | command: 'restore' |
| 31 | projects: 'MyApp.sln' |
| 32 | |
| 33 | - task: DotNetCoreCLI@2 |
| 34 | displayName: 'Build' |
| 35 | inputs: |
| 36 | command: 'build' |
| 37 | projects: 'MyApp.sln' |
| 38 | arguments: '-c Release --no-restore' |
| 39 | ``` |
| 40 | |
| 41 | ### Test |
| 42 | |
| 43 | ```yaml |
| 44 | - task: DotNetCoreCLI@2 |
| 45 | displayName: 'Run tests' |
| 46 | inputs: |
| 47 | command: 'test' |
| 48 | projects: '**/*Tests.csproj' |
| 49 | arguments: >- |
| 50 | -c Release |
| 51 | --logger "trx;LogFileName=test-results.trx" |
| 52 | --results-directory $(Build.ArtifactStagingDirectory)/test-results |
| 53 | ``` |
| 54 | |
| 55 | ### Pack |
| 56 | |
| 57 | ```yaml |
| 58 | - task: DotNetCoreCLI@2 |
| 59 | displayName: 'Pack NuGet packages' |
| 60 | inputs: |
| 61 | command: 'pack' |
| 62 | packagesToPack: 'src/**/*.csproj' |
| 63 | configuration: 'Release' |
| 64 | outputDir: '$(Build.ArtifactStagingDirectory)/nupkgs' |
| 65 | nobuild: true |
| 66 | ``` |
| 67 | |
| 68 | ### Custom Command |
| 69 | |
| 70 | For commands not directly supported by the task (e.g., `dotnet tool install`): |
| 71 | |
| 72 | ```yaml |
| 73 | - task: DotNetCoreCLI@2 |
| 74 | displayName: 'Install dotnet tools' |
| 75 | inputs: |
| 76 | command: 'custom' |
| 77 | custom: 'tool' |
| 78 | arguments: 'restore' |
| 79 | ``` |
| 80 | |
| 81 | ### Multi-Version SDK Install |
| 82 | |
| 83 | Install multiple SDK versions for multi-TFM builds: |
| 84 | |
| 85 | ```yaml |
| 86 | - task: UseDotNet@2 |
| 87 | displayName: 'Install .NET 8' |
| 88 | inputs: |
| 89 | packageType: 'sdk' |
| 90 | version: '8.0.x' |
| 91 | |
| 92 | - task: UseDotNet@2 |
| 93 | displayName: 'Install .NET 9' |
| 94 | inputs: |
| 95 | packageType: 'sdk' |
| 96 | version: '9.0.x' |
| 97 | ``` |
| 98 | |
| 99 | Each `UseDotNet@2` invocation adds the SDK version to PATH. The last installed version becomes the default, but all versions are available via `--framework` targeting. |
| 100 | |
| 101 | --- |
| 102 | |
| 103 | ## NuGet Restore with Azure Artifacts Feeds |
| 104 | |
| 105 | ### `NuGetAuthenticate@1` for Feed Authentication |
| 106 | |
| 107 | ```yaml |
| 108 | steps: |
| 109 | - task: NuGetAuthenticate@1 |
| 110 | displayName: 'Authenticate NuGet feeds' |
| 111 | |
| 112 | - task: DotNetCoreCLI@2 |
| 113 | displayName: 'Restore' |
| 114 | inputs: |
| 115 | command: 'restore' |
| 116 | projects: 'MyApp.sln' |
| 117 | feedsToUse: 'config' |
| 118 | nugetConfigPath: 'nuget.config' |
| 119 | ``` |
| 120 | |
| 121 | The `NuGetAuthenticate@1` task configures credentials for all Azure Artifacts feeds referenced in `nuget.config`. No explicit PAT or API key is needed -- the task uses the pipeline's identity. |
| 122 | |
| 123 | ### Selecting Feeds Directly |
| 124 | |
| 125 | For simple setups without a `nuget.config`, select feeds directly in the restore task: |
| 126 | |
| 127 | ```yaml |
| 128 | - task: DotNetCoreCLI@2 |
| 129 | displayName: 'Restore with Azure Artifacts' |
| 130 | inputs: |
| 131 | command: 'restore' |
| 132 | projects: 'MyApp.sln' |
| 133 | feedsToUse: 'select' |
| 134 | vstsFeed: 'MyProject/MyFeed' |
| 135 | includeNuGetOrg: true |
| 136 | ``` |
| 137 | |
| 138 | ### Upstream Sources |
| 139 | |
| 140 | Azure Artifacts feeds can proxy nuget.org as an upstream source. When configured, a single feed reference provides access to both private packages and public NuGet packages: |
| 141 | |
| 142 | ```xml |
| 143 | <!-- nuget.config with Azure Artifacts upstream --> |
| 144 | <?xml version="1.0" encoding="utf-8"?> |
| 145 | <configuration> |
| 146 | <packageSources> |
| 147 | <clear /> |
| 148 | <add key="MyFeed" value="https://pkgs.dev.azure.com/myorg/_packaging/myfeed/nuget/v3/index.json" /> |
| 149 | </packageSources> |
| 150 | </configuration> |
| 151 | ``` |
| 152 | |
| 153 | With upstream sourc |