Why GitHub Actions?
GitHub Actions is free for public repos, tightly integrated with your code, and has thousands of community actions. It's the default choice for .NET CI/CD in 2025.
Complete Workflow
name: CI/CD
on:
push:
branches: [main]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '10.0.x'
- run: dotnet restore
- run: dotnet test --no-restore
- run: dotnet publish -c Release -o publish
- uses: azure/webapps-deploy@v3
with:
app-name: my-app
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
package: publish
âš ï¸
Never hardcode secrets in workflow files. Use GitHub Secrets (Settings → Secrets) for connection strings, API keys, and publish profiles.
Caching Dependencies
- uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: nuget-${{ hashFiles('**/*.csproj') }}
This alone cuts build time from 3 minutes to under 30 seconds on subsequent runs.