Back to results for “.NET CLI”
.NET › CI/CD, Publishing & Deployment

How do you configure a GitHub Actions workflow to build, test, and publish a .NET application?

Intermediate

Answer

A GitHub Actions workflow YAML file defines jobs with steps using the actions/setup-dotnet action to install the required SDK version, followed by standard dotnet CLI commands, with results and artifacts optionally uploaded using actions/upload-artifact for use in subsequent deployment jobs.
name: CI
on: [push, pull_request]
jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-dotnet@v4
        with: { dotnet-version: '8.0.x' }
      - run: dotnet restore
      - run: dotnet build --no-restore -c Release
      - run: dotnet test --no-build -c Release --logger trx
      - uses: actions/upload-artifact@v4
        with: { name: test-results, path: '**/*.trx' }
Real-world example A team's GitHub Actions workflow runs on every pull request, automatically posting test results and coverage reports as a PR comment before a reviewer even opens the code, catching issues early in the review process.

Common follow-ups: How do you cache NuGet packages between workflow runs to speed up builds?;How do you set up matrix builds testing against multiple .NET versions?