๐ .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 |
๐ Related Actions
| 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
- Enable Debug Mode: Set
ACTIONS_STEP_DEBUG: true - Use Diagnostic Verbosity: Set
verbosity: "diagnostic" - Check Executed Command: Use the
executed-commandoutput - 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.