1node.si
← Registry

gh-actions-dotnet-build

cleared

Builds .NET projects in GitHub Actions using actions/setup-dotnet with a standard restore → build → publish pipeline, output under an artifacts folder, and optional dotnet test when tests are requested or test projects exist. Use when authoring or fixing GitHub workflows for .NET, SDK pinning, or CI before deploy (e.g. Azure Web App package layout).

files.jsonSKILL.md
---
name: gh-actions-dotnet-build
description: >-
  Builds .NET projects in GitHub Actions using actions/setup-dotnet with a
  standard restore → build → publish pipeline, output under an artifacts folder,
  and optional dotnet test when tests are requested or test projects exist. Use
  when authoring or fixing GitHub workflows for .NET, SDK pinning, or CI before
  deploy (e.g. Azure Web App package layout).
---

# GitHub Actions: .NET build and publish

Official SDK action: [actions/setup-dotnet](https://github.com/actions/setup-dotnet).

## Minimal pipeline

On **`ubuntu-latest`** (or Linux-compatible self-hosted runners):

1. **`actions/checkout`**
2. **`actions/setup-dotnet`** — pin **`dotnet-version`** (e.g. **`8.0.x`**, **`9.0.x`**) or use **`global.json`** / multi-version support per upstream docs.
3. **`dotnet restore`** — target the app **`.csproj`** or **`.sln`** the repo builds.
4. **`dotnet build`** — **`--configuration Release --no-restore`** (same target as restore).
5. **`dotnet publish`** — **`--configuration Release --no-restore --output ./artifacts`** (or **`./artifacts/<app>`** in monorepos). Add **`/p:...`** when needed (e.g. **`/p:EnvironmentName=Production`** for config transforms).

Resolve **`uses:`** majors with **`update-github-actions-versions`**.

## Tests (conditional)

Add **`dotnet test`** when:

- The user asks for tests in CI, or
- The repo has test projects (e.g. **`*.Tests.csproj`**, **`*UnitTests*.csproj`**, **`test/**`**, **`tests/**`**).

Use the **test project** or **solution** path. Typical flags: **`--configuration Release --no-restore`**. Place **Test** between **Build** and **Publish**.

## Artifacts folder

- **Default:** **`./artifacts`** (relative to **`github.workspace`**).
- **Subfolders** (e.g. **`./artifacts/web`**) help multi-project repos; align with deploy (**`azure/webapps-deploy`** **`package:`**).

Optionally **`actions/upload-artifact`** for a later deploy job; same-job deploy can use the folder directly.

**Full-stack:** run **`gh-actions-nodejs-build`** steps first (frontends into **`wwwroot`** or paths the `.csproj` expects), then **`dotnet publish`**.

## Project paths

Use paths from the repository (solution, main web `.csproj`, `Directory.Build.props`). Examples in this skill use **`src/MyApp/MyApp.Web.csproj`** and **`tests/MyApp/MyApp.Web.Tests.csproj`**.

## Step identifiers

Give each step an **`id:`** (e.g. **`setup_dotnet`**, **`restore`**, **`build`**, **`test`**, **`publish`**) per **`ci-cd-pipeline-foundation`**.

## YAML templates

See [reference.md](reference.md).