← Registry
ado-dotnet-build-publish
clearedAzure Pipelines .NET CI using DotNetCoreCLI@2 for restore, build, and publish, plus PublishBuildArtifacts@1. Covers Linux zip publish, Windows MSDeploy web package patterns, optional extra artifacts (publish profiles), and variable groups with local csproj/sln paths. Use when authoring ADO YAML for .NET before git deploy, Azure Web App deployment, or manual release.
--- name: ado-dotnet-build-publish description: >- Azure Pipelines .NET CI using DotNetCoreCLI@2 for restore, build, and publish, plus PublishBuildArtifacts@1. Covers Linux zip publish, Windows MSDeploy web package patterns, optional extra artifacts (publish profiles), and variable groups with local csproj/sln paths. Use when authoring ADO YAML for .NET before git deploy, Azure Web App deployment, or manual release. --- # Azure Pipelines: .NET build and publish ## Prerequisites - Solution / project paths known (`*.sln`, `*.csproj`). - Variable group(s) for shared non-secret settings and secrets (NuGet feeds, connection strings if needed at build time). - Target framework and publish style agreed (Linux zip vs Windows web-deploy package). ## Layout 1. **`variables:`** — `group:` for shared settings; local `csproj` / `sln` path variables (see **`ci-cd-pipeline-foundation`**). 2. **`stages`** — Build job on `ubuntu-latest`, or `windows-*` when MSDeploy / IIS packaging needs Windows. 3. **`DotNetCoreCLI@2`** — `restore` (solution), `build`, then `publish` with `publishWebProjects: false` when targeting a specific `.csproj`. 4. **`PublishBuildArtifacts@1`** — publish `$(Build.ArtifactStagingDirectory)/...` or the zip output folder. Give every task a `name:` and `displayName:`. ## Publish modes | Mode | Typical `arguments` / inputs | |------|------------------------------| | **Linux folder + zip** | `-c Release -o $(Build.ArtifactStagingDirectory)/MyApp.Web` with `zipAfterPublish: true` → one zip for `AzureRmWebAppDeployment@4` `packageForLinux` | | **Windows web deploy package** | `/p:WebPublishMethod=Package /p:PackageAsSingleFile=true` and `PackageLocation` under `Build.ArtifactStagingDirectory`; set `zipAfterPublish: false` when the publish task already emits the package folder + `.zip` | Discover MSBuild properties from the repo; do not assume paths from unrelated samples. ## Full-stack (Node + .NET) Run frontend `npm` / `yarn` steps (see **`ado-nodejs-build`**) **before** `DotNetCoreCLI@2` when static files must land in `wwwroot` or another publish output folder. ## Tests Add `DotNetCoreCLI@2` with `command: test` when tests are required or `*.Tests.csproj` exists—typically between build and publish. ## Downstream deploy - **Git deploy + ExtractFiles** — align artifact name and zip path with **`cd-azure-devops-git-deploy`**. - **Azure Web App** — **`ado-azure-webapp-deployment`**. - **Linux zip + StartupCommand** — the published zip path must match `packageForLinux`. ## YAML See [reference.md](reference.md) for Linux and Windows skeletons.