Using GitHub Actions to create a .NET Framework pipeline: Build, test, and deploy
A step-by-step guide to setting up a CI/CD pipeline for a .NET Framework project using GitHub Actions — build, test with VSTest, restore NuGet packages, and run the application automatically.
In this article we cover the CI/CD process of a .NET Framework project using GitHub Actions to build, test, and run — from the first workflow file to a complete automated pipeline.
What are GitHub Actions?
GitHub Actions provides a flexible way to automate various tasks directly from your GitHub repositories — building, testing, and deploying applications. These actions are defined in YAML files as workflows and can be customized to suit your project’s specific requirements.
For reference, I set up a repository on GitHub with a PoC (Proof of Concept) based on this tutorial. That repository has many more features than what I cover here:
Creating the pipeline — step by step
Step 1 — Open the Actions tab
Open your repository on GitHub and click on the Actions tab.
Step 2 — Set up a workflow yourself
GitHub provides numerous workflow templates for different languages and frameworks. To write your own from scratch, click Set up a workflow yourself above the Choose a workflow section.
Step 3 — Name the workflow and define triggers
In the GitHub Actions editor, name the workflow and define the events that will fire it:
name: Build .NET Framework
on:
push:
workflow_dispatch:
pushfires the workflow on every push to the repository.workflow_dispatchallows running the workflow manually from the Actions page.
A complete reference of all trigger events is in the official GitHub Actions documentation.
Step 4 — Define the build job on a Windows runner
.NET Framework requires a Windows environment. Create a job and target windows-latest:
jobs:
build:
name: Build
runs-on: windows-latest
The runs-on value is job-scoped — different jobs in the same workflow can target different operating systems.
Step 5 — Configure the job steps
The job needs the following steps in order:
- Checkout the source code
- Set up MSBuild
- Set up VSTest
- Set up NuGet
- Restore NuGet packages
- Build the solution in Release mode
- Run the tests
- (Optional) Run the compiled executable
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup MSBuild Path
uses: microsoft/setup-msbuild@v1.3
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Setup VSTest
uses: darenm/Setup-VSTest@v1.2
- name: Setup NuGet
uses: NuGet/setup-nuget@v1.2
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Restore NuGet Packages
run: nuget restore your-solution-name.sln
- name: Build Release
run: msbuild your-solution-name.sln /p:Configuration=Release
- name: Test
run: vstest.console.exe path-to-test-binary.dll
- name: Run
run: path-to-application-binary.exe
your-solution-name.sln with the actual path to your solution file in both the Restore and Build steps. Replace path-to-test-binary.dll with the DLL path of the test project after a Release build — usually inside bin/Release/. Replace path-to-application-binary.exe with the path to the compiled executable of your main project.
Steps 6 and 7 — Save, trigger, and monitor
Save the workflow file — it lives at .github/workflows/build.yml in your repository. GitHub Actions triggers it automatically on the next push, or you can run it manually from the Actions tab. Each run shows a full view of progress, logs, and error details.
Complete workflow file
Here is the full workflow to build, test, and run a .NET Framework solution:
name: Build .NET Framework
on:
push:
workflow_dispatch:
jobs:
build:
name: Build
runs-on: windows-latest
steps:
- name: Checkout Code
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup MSBuild Path
uses: microsoft/setup-msbuild@v1.3
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Setup VSTest
uses: darenm/Setup-VSTest@v1.2
- name: Setup NuGet
uses: NuGet/setup-nuget@v1.2
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
- name: Restore NuGet Packages
run: nuget restore your-solution-name.sln
- name: Build Release
run: msbuild your-solution-name.sln /p:Configuration=Release
- name: Test
run: vstest.console.exe path-to-test-binary.dll
- name: Run
run: path-to-application-binary.exe
Benefits of GitHub Actions for your projects
References
- GitHub. Official GitHub Actions documentation. docs.github.com/en/actions
- actions/checkout. GH Action: actions/checkout. github.com/actions/checkout
- Microsoft. GH Action: microsoft/setup-msbuild. github.com/microsoft/setup-msbuild
- darenm. GH Action: darenm/Setup-VSTest. github.com/darenm/Setup-VSTest
- NuGet. GH Action: NuGet/setup-nuget. github.com/NuGet/setup-nuget