Github Actions for c# projects

cd your\working\directory
git clone git@github.com:MichaelSvendsen/githubactions.git
cd githubactions
git remote set-url origin <link-to-your-new-repo>
git push -u origin master
cd ..
git clone <link-to-your-new-repo>
cd <your-new-repo-name>
.gitgub\workflows\ations.yml
name: Validation of Console App
on:
pull_request:
branches: [ master, develop, release/*, hotfix/* ]
jobs:
run-selected-unittests:
runs-on: windows-latest
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
name: Run MSBuild and VSTest

steps:
- name: Checkout code
uses: actions/checkout@v2.1.0
id: checkout_code

- name: Setup MSBuild and add to PATH
uses: microsoft/setup-msbuild@v1.0.0
id: setup_msbuild

- name: Run MSBuild
id: run_msbuild
run: |
msbuild .\gitactionstest.sln /t:clean /p:Configuration=Debug
nuget restore .\gitactionstest.sln
msbuild .\gitactionstest.sln /t:build /p:Configuration=Debug
- name: Setup VSTest and add to PATH
uses: darenm/Setup-VSTest@v1
id: setup_vstest
- name: Test Case Workers
id: run_vstest
working-directory: UnitTests\bin\Debug
run: vstest.console.exe .\UnitTests.dll /Tests:TestCaseWorkerIds,TestCaseWorkersCount
  1. Run for updates to pull requests for repos master, develop, release/* and hotfix/* (you can see that this setup is inspired by gitflow)
  2. Run the actions on the latest version of windows (windows-latest)
  3. Set an environment variable to be able to run msbuild on our code
  4. Checkout the code in the repository
  5. Download and configure msbuild
  6. Build the console application (including using nuget to get packages)
  7. Download and configure VSTest
  8. Run the unittests with VSTest
A clean run of the actions
git checkout master
git pull
git checkout -b Break-Something
...namespace gitactionstest
{
public class Cases
{
public enum CaseWorkers
{
Joe = 1,
Jane = 2,
Michelle = 3,
Mark = 4
}
}
}
git add Cases.cs
git commit -m "New Case Worker Michelle added"
git push --set-upstream origin Break-Something
...namespace gitactionstest
{
public class Cases
{
public enum CaseWorkers
{
Joe = 1,
Jane = 2,
Mark = 3,
Michelle = 4
}
}
}
...namespace UnitTests
{
[TestClass]
public class CaseWorkerTests
{
[TestMethod]
public void TestCaseWorkerIds()
{
Assert.IsTrue((int)Cases.CaseWorkers.Joe == 1);
Assert.IsTrue((int)Cases.CaseWorkers.Jane == 2);
Assert.IsTrue((int)Cases.CaseWorkers.Mark == 3);
Assert.IsTrue((int)Cases.CaseWorkers.Michelle == 4);
}
[TestMethod]
public void TestCaseWorkersCount()
{
Assert.IsTrue(Enum.GetNames(typeof(Cases.CaseWorkers)).Length == 4);
}
}
}

--

--

--

CTO @ SimpleSite.com, Computer Scientist, nerd with a sense for business

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Is your database environment meeting your business growth needs?

Gaming and Development Workstation Guide: Dual Boot

1 Year Later Flutter Web Still Sucks

A laptop

Top 10 Interview Question for Flutter App Developer

Cycan Weekly Report 2022/02/11

Deploying Next Gen Serverless Functions with WebAssembly and Module Federation

Behind the Screens: Rafaele Andrade

Right Disk Type for performance

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Michael Svendsen

Michael Svendsen

CTO @ SimpleSite.com, Computer Scientist, nerd with a sense for business

More from Medium

Migrate ASP.Net core from 5.0 to 6.0

ConfIT: Declarative Integration Tests

Easy Modular Monolith — Part 6 — Synchronous communication between modules

Building a Platform: Part 2