Skip to content

Instantly share code, notes, and snippets.

@0x49D1
Last active July 8, 2025 11:50
Show Gist options
  • Save 0x49D1/d8b35be4e438a84794a3c41e0b804522 to your computer and use it in GitHub Desktop.
Save 0x49D1/d8b35be4e438a84794a3c41e0b804522 to your computer and use it in GitHub Desktop.
Script is a sample to run .NET projects from specific directory and subdirectories by pattern (for example run all "API" services from "sharedservices" directory) at once without need of any tools on any OS, just need a terminal with bash support.
#!/usr/bin/env bash
# Generic script to build and run all .NET projects from a given directory recursively by pattern
set -e
if [ $# -lt 2 ]; then
echo "Usage: $0 <directory> <pattern>"
echo "Example: $0 ../sharedservices '*.Api.csproj'"
exit 1
fi
SEARCH_DIR="$1"
PATTERN="$2"
# Ensure all child processes are killed on exit (including on Ctrl+C or terminal close)
trap 'echo "Killing all child processes..."; kill 0' SIGINT SIGTERM EXIT
# Build and run all matching projects
find "$SEARCH_DIR" -name "$PATTERN" | while read -r csproj; do
echo "Building $csproj..."
dotnet build "$csproj" -c Debug
echo "Running $csproj in debug mode..."
dotnet run --project "$csproj" -c Debug &
done
echo "All matching projects are starting in debug mode."
wait
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment