๐Ÿš€ .NET Command Action

A comprehensive GitHub Action for executing .NET CLI commands with intelligent argument parsing, automatic verbosity handling, and cross-platform support.

โœจ Features

  • ๐ŸŽฏ Smart Command Execution - Automatic detection of supported options per .NET command
  • ๐Ÿ”ง Auto-Verbosity Detection - Adjusts verbosity based on debug settings
  • ๐Ÿ“‹ Flexible Arguments - String and YAML array support for complex scenarios
  • โœ… Comprehensive Validation - Input validation with helpful error messages
  • โšก Performance Optimized - Cached command support maps
  • ๐Ÿ›ก๏ธ Cross-Platform - Works on Windows, Linux, and macOS runners
  • ๐Ÿ“Š Detailed Reporting - Rich summaries with execution metrics

๐Ÿš€ Basic Usage

Minimal configuration to get started:

- name: "Build project"
  uses: laerdal/github_actions/dotnet@main
  with:
    command: "build"
- name: "Run tests"
  uses: laerdal/github_actions/dotnet@main
  with:
    command: "test"
- name: "Restore packages"
  uses: laerdal/github_actions/dotnet@main
  with:
    command: "restore"

๐Ÿ”ง Advanced Usage

Full configuration with all available options:

- name: "Advanced .NET build and publish"
  uses: laerdal/github_actions/dotnet@main
  with:
    command: "publish"
    path: "./src/MyApp/MyApp.csproj"
    working-directory: "./backend"
    configuration: "Release"
    framework: "net8.0"
    runtime: "linux-x64"
    arch: "x64"
    output: "./dist"
    verbosity: "detailed"
    nologo: "true"
    no-restore: "false"
    no-build: "false"
    show-summary: "true"
    arguments: |
      --self-contained
      --no-dependencies
      /p:PublishSingleFile=true
      /p:IncludeNativeLibrariesForSelfExtract=true

๐Ÿ” Permissions Required

This action requires standard repository permissions:

permissions:
  contents: read  # Required to checkout repository code

Note: No additional permissions are required as this action only executes .NET CLI commands on the runner.

๐Ÿ—๏ธ CI/CD Example

Complete workflow for .NET application:

name: "CI/CD Pipeline"

on:
  push:
    branches: ["main", "develop"]
  pull_request:
    branches: ["main"]

permissions:
  contents: read

jobs:
  build-and-test:
    runs-on: ubuntu-latest

    steps:
      - name: "๐Ÿ“ฅ Checkout repository"
        uses: actions/checkout@v4

      - name: "๐Ÿ”ง Setup .NET"
        uses: actions/setup-dotnet@v4
        with:
          dotnet-version: "8.0.x"

      - name: "๐Ÿ“ฆ Restore dependencies"
        uses: laerdal/github_actions/dotnet@main
        with:
          command: "restore"
          verbosity: "minimal"

      - name: "๐Ÿ—๏ธ Build solution"
        uses: laerdal/github_actions/dotnet@main
        with:
          command: "build"
          configuration: "Release"
          no-restore: "true"
          show-summary: "true"

      - name: "๐Ÿงช Run tests"
        uses: laerdal/github_actions/dotnet@main
        with:
          command: "test"
          configuration: "Release"
          no-build: "true"
          arguments: "--collect:\"XPlat Code Coverage\" --logger trx"

      - name: "๐Ÿš€ Publish application"
        if: github.ref == 'refs/heads/main'
        uses: laerdal/github_actions/dotnet@main
        with:
          command: "publish"
          path: "./src/WebApp/WebApp.csproj"
          configuration: "Release"
          runtime: "linux-x64"
          output: "./publish"
          arguments: "--self-contained"

๐Ÿ“‹ Inputs

Input Description Required Default Example
command .NET command to execute โœ… Yes - build, test, restore, publish
path Path to project/solution file or directory โŒ No "" ./src/MyProject.csproj
arguments Additional command arguments โŒ No "" --no-dependencies
working-directory Working directory for command execution โŒ No "." ./backend
verbosity Force specific verbosity level โŒ No "" quiet, minimal, normal, detailed, diagnostic
nologo Suppress Microsoft logo and startup info โŒ No "true" true, false
no-restore Skip automatic restore โŒ No "false" true, false
no-build Skip building before running โŒ No "false" true, false
configuration Build configuration โŒ No "Release" Debug, Release
framework Target framework โŒ No "" net8.0, net6.0
runtime Target runtime identifier โŒ No "" win-x64, linux-x64, osx-arm64
arch Target architecture โŒ No "" x86, x64, arm, arm64
output Output directory path โŒ No "" ./bin, ./publish
show-summary Display action summary โŒ No "false" true, false

๐Ÿ“ค Outputs

Output Description Type Example
exit-code Exit code of the executed command string 0, 1
executed-command Full command that was executed string dotnet build --configuration Release
Action Purpose Repository
๐Ÿงช dotnet-test Enhanced .NET testing with coverage laerdal/github_actions/dotnet-test
๐Ÿ”ง dotnet-tool-install Install .NET tools laerdal/github_actions/dotnet-tool-install
๐Ÿ“ฆ dotnet-nuget-upload Upload NuGet packages laerdal/github_actions/dotnet-nuget-upload
๐Ÿ“š dotnet-docfx-build Generate documentation laerdal/github_actions/dotnet-docfx-build
๐Ÿ” dotnet-cyclonedx Generate SBOM files laerdal/github_actions/dotnet-cyclonedx

๐Ÿ’ก Examples

Building Multiple Configurations

- name: "Build Debug"
  uses: laerdal/github_actions/dotnet@main
  with:
    command: "build"
    configuration: "Debug"

- name: "Build Release"
  uses: laerdal/github_actions/dotnet@main
  with:
    command: "build"
    configuration: "Release"

Multi-Framework Testing

strategy:
  matrix:
    framework: ["net6.0", "net8.0"]

steps:
  - name: "Test ${{ matrix.framework }}"
    uses: laerdal/github_actions/dotnet@main
    with:
      command: "test"
      framework: ${{ matrix.framework }}

Cross-Platform Publishing

strategy:
  matrix:
    runtime: ["win-x64", "linux-x64", "osx-arm64"]

steps:
  - name: "Publish for ${{ matrix.runtime }}"
    uses: laerdal/github_actions/dotnet@main
    with:
      command: "publish"
      runtime: ${{ matrix.runtime }}
      output: "./dist/${{ matrix.runtime }}"

Complex Arguments with YAML

- name: "Create NuGet package"
  uses: laerdal/github_actions/dotnet@main
  with:
    command: "pack"
    path: "./src/MyLibrary/MyLibrary.csproj"
    configuration: "Release"
    output: "./packages"
    arguments: |
      --include-symbols
      --include-source
      /p:PackageVersion=1.0.0
      /p:Authors="Framinosona"

๐Ÿ”ง Command Support Matrix

Command Verbosity Configuration Framework Runtime No-Restore No-Build Output
build โœ… โœ… โœ… โœ… โœ… โŒ โœ…
restore โœ… โŒ โŒ โŒ โŒ โŒ โŒ
test โœ… โœ… โœ… โœ… โœ… โœ… โŒ
publish โœ… โœ… โœ… โœ… โœ… โœ… โœ…
pack โœ… โœ… โœ… โœ… โœ… โŒ โœ…
run โŒ โœ… โœ… โœ… โŒ โŒ โŒ
clean โœ… โŒ โŒ โŒ โŒ โŒ โŒ

๐Ÿ› Troubleshooting

Common Issues

.NET SDK Not Found

Problem: dotnet command not available

Solution: Add .NET setup before this action:

- name: "Setup .NET"
  uses: actions/setup-dotnet@v4
  with:
    dotnet-version: "8.0.x"

Invalid Path Error

Problem: Specified path does not exist

Solution: Verify file/directory exists:

- name: "Check path exists"
  run: ls -la ./src/MyProject.csproj

Build Failures

Problem: Build errors with complex arguments

Solution: Use YAML array format for complex arguments:

arguments: |
  --configuration Release
  --runtime linux-x64
  --self-contained

Debug Tips

  1. Enable Debug Mode: Set ACTIONS_STEP_DEBUG: true
  2. Use Diagnostic Verbosity: Set verbosity: "diagnostic"
  3. Check Executed Command: Use the executed-command output
  4. Enable Summary: Set show-summary: "true"

๐Ÿ“ Requirements

  • GitHub Actions runner (Windows, Linux, or macOS)
  • .NET SDK installed (use actions/setup-dotnet)
  • Valid .NET project or solution structure
  • Bash shell (available on all runners)

๐Ÿ“„ License

This action is part of the GitHub Actions collection by Francois Raminosona.


๐Ÿ’ก Tip: For more complex .NET workflows, check out our specialized actions in the Related Actions section.