$npx -y skills add wshaddix/dotnet-skills --skill dotnet-add-ciAdding CI/CD to a .NET project. GitHub Actions vs Azure DevOps detection, workflow templates.
| 1 | # dotnet-add-ci |
| 2 | |
| 3 | Add starter CI/CD workflows to an existing .NET project. Detects the hosting platform (GitHub Actions or Azure DevOps) and generates an appropriate starter workflow for build, test, and pack. |
| 4 | |
| 5 | **Scope boundary:** This skill provides **starter templates** only. For advanced CI/CD patterns — composable reusable workflows, matrix builds, deployment pipelines, release automation, and environment promotion — see [skill:dotnet-gha-patterns], [skill:dotnet-ado-patterns], and related CI/CD depth skills. |
| 6 | |
| 7 | **Prerequisites:** Run [skill:dotnet-version-detection] first to determine SDK version for the workflow. Run [skill:dotnet-project-analysis] to understand solution structure. |
| 8 | |
| 9 | Cross-references: [skill:dotnet-project-structure] for build props layout, [skill:dotnet-scaffold-project] which generates the project structure these workflows build. |
| 10 | |
| 11 | --- |
| 12 | |
| 13 | ## Platform Detection |
| 14 | |
| 15 | Detect the CI platform from existing repo indicators: |
| 16 | |
| 17 | | Indicator | Platform | |
| 18 | |-----------|----------| |
| 19 | | `.github/` directory exists | GitHub Actions | |
| 20 | | `azure-pipelines.yml` exists | Azure DevOps | |
| 21 | | `.github/workflows/` has YAML files | GitHub Actions (already configured) | |
| 22 | | Neither | Ask the user which platform to target | |
| 23 | |
| 24 | --- |
| 25 | |
| 26 | ## GitHub Actions Starter Workflow |
| 27 | |
| 28 | Create `.github/workflows/build.yml`: |
| 29 | |
| 30 | ```yaml |
| 31 | name: Build and Test |
| 32 | |
| 33 | on: |
| 34 | push: |
| 35 | branches: [main] |
| 36 | pull_request: |
| 37 | branches: [main] |
| 38 | |
| 39 | permissions: |
| 40 | contents: read |
| 41 | |
| 42 | env: |
| 43 | DOTNET_NOLOGO: true |
| 44 | DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 45 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 46 | |
| 47 | jobs: |
| 48 | build: |
| 49 | runs-on: ubuntu-latest |
| 50 | |
| 51 | steps: |
| 52 | - uses: actions/checkout@v4 |
| 53 | |
| 54 | - name: Setup .NET |
| 55 | uses: actions/setup-dotnet@v4 |
| 56 | with: |
| 57 | global-json-file: global.json |
| 58 | |
| 59 | - name: Restore |
| 60 | run: dotnet restore --locked-mode |
| 61 | |
| 62 | - name: Build |
| 63 | run: dotnet build --no-restore -c Release |
| 64 | |
| 65 | - name: Test |
| 66 | run: dotnet test --no-build -c Release --logger trx --results-directory TestResults |
| 67 | |
| 68 | - name: Upload test results |
| 69 | uses: actions/upload-artifact@v4 |
| 70 | if: always() |
| 71 | with: |
| 72 | name: test-results |
| 73 | path: TestResults/**/*.trx |
| 74 | ``` |
| 75 | |
| 76 | ### Key Decisions Explained |
| 77 | |
| 78 | - **`global-json-file`** — uses the repo's `global.json` to install the exact SDK version. If the project has no `global.json`, replace with `dotnet-version: '10.0.x'` (or the appropriate version) |
| 79 | - **`--locked-mode`** — ensures `packages.lock.json` files are respected; fails if they're out of date. If the project doesn't use lock files, replace with plain `dotnet restore` |
| 80 | - **`-c Release`** — builds in Release mode so `ContinuousIntegrationBuild` takes effect |
| 81 | - **`permissions: contents: read`** — principle of least privilege |
| 82 | - **Environment variables** — suppress .NET CLI noise in logs |
| 83 | |
| 84 | ### Adding NuGet Pack (Libraries) |
| 85 | |
| 86 | For projects that publish to NuGet, add a pack step: |
| 87 | |
| 88 | ```yaml |
| 89 | - name: Pack |
| 90 | run: dotnet pack --no-build -c Release -o artifacts |
| 91 | |
| 92 | - name: Upload packages |
| 93 | uses: actions/upload-artifact@v4 |
| 94 | with: |
| 95 | name: nuget-packages |
| 96 | path: artifacts/*.nupkg |
| 97 | ``` |
| 98 | |
| 99 | --- |
| 100 | |
| 101 | ## Azure DevOps Starter Pipeline |
| 102 | |
| 103 | Create `azure-pipelines.yml` at the repo root: |
| 104 | |
| 105 | ```yaml |
| 106 | trigger: |
| 107 | branches: |
| 108 | include: |
| 109 | - main |
| 110 | |
| 111 | pr: |
| 112 | branches: |
| 113 | include: |
| 114 | - main |
| 115 | |
| 116 | pool: |
| 117 | vmImage: 'ubuntu-latest' |
| 118 | |
| 119 | variables: |
| 120 | DOTNET_NOLOGO: true |
| 121 | DOTNET_CLI_TELEMETRY_OPTOUT: true |
| 122 | DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true |
| 123 | buildConfiguration: 'Release' |
| 124 | |
| 125 | steps: |
| 126 | - task: UseDotNet@2 |
| 127 | displayName: 'Setup .NET SDK' |
| 128 | inputs: |
| 129 | useGlobalJson: true |
| 130 | |
| 131 | - script: dotnet restore --locked-mode |
| 132 | displayName: 'Restore' |
| 133 | |
| 134 | - script: dotnet build --no-restore -c $(buildConfiguration) |
| 135 | displayName: 'Build' |
| 136 | |
| 137 | - task: DotNetCoreCLI@2 |
| 138 | displayName: 'Test' |
| 139 | inputs: |
| 140 | command: 'test' |
| 141 | arguments: '--no-build -c $(buildConfiguration) --logger trx' |
| 142 | publishTestResults: true |
| 143 | ``` |
| 144 | |
| 145 | ### Adding NuGet Pack (Libraries) |
| 146 | |
| 147 | ```yaml |
| 148 | - script: dotnet pack --no-build -c $(buildConfiguration) -o $(Build.ArtifactStagingDirectory) |
| 149 | displayName: 'Pack' |
| 150 | |
| 151 | - task: PublishBuildArtifacts@1 |
| 152 | displayName: 'Publish NuGet packages' |
| 153 | inputs: |
| 154 | pathToPublish: '$(Build.ArtifactStagingDirectory)' |
| 155 | artifactName: 'nuget-packages' |
| 156 | ``` |
| 157 | |
| 158 | --- |
| 159 | |
| 160 | ## Adapting the Starter Workflow |
| 161 | |
| 162 | ### Multi-TFM Projects |
| 163 | |
| 164 | If the project multi-targets, the default workflow works without changes — `dotnet build` and `dotnet test` handle all TFMs automatically. No matrix is needed for the starter. |
| 165 | |
| 166 | ### Windows-Only Projects (MAUI, WPF, WinForms) |
| 167 | |
| 168 | Change the runner: |
| 169 | |
| 170 | ```yaml |
| 171 | # GitHub Actions |
| 172 | runs-on: windows-latest |
| 173 | |
| 174 | # Azure DevOps |
| 175 | pool: |
| 176 | vmImage: 'windows-latest' |
| 177 | ``` |
| 178 | |
| 179 | ### Solution Filter |
| 180 | |
| 181 | If the repo has multiple solutions or uses solution filters: |
| 182 | |
| 183 | ```yaml |
| 184 | - name: Build |
| 185 | run: dotnet build MyApp.slnf -- |