GitHub Actions is now my go-to for .NET CI/CD. It’s free for public repos, integrated with GitHub, and surprisingly powerful. Here’s a complete guide.
Basic .NET Workflow
name: .NET Build and Test
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Setup .NET
uses: actions/setup-dotnet@v1
with:
dotnet-version: 3.1.x
- name: Restore
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release
- name: Test
run: dotnet test --no-build -c Release --logger trx
- name: Publish Test Results
uses: dorny/test-reporter@v1
if: always()
with:
name: Test Results
path: '**/*.trx'
reporter: dotnet-trx
Deploy to Azure
- name: Deploy to Azure Web App
uses: azure/webapps-deploy@v2
with:
app-name: 'my-app'
publish-profile: ${{ secrets.AZURE_PUBLISH_PROFILE }}
package: './publish'
Tips
- Cache NuGet packages for faster builds
- Use matrix builds to test multiple .NET versions
- Store secrets in GitHub Secrets
- Use workflow dispatch for manual triggers
References
Discover more from C4: Container, Code, Cloud & Context
Subscribe to get the latest posts sent to your email.