TheSharperDev

Posts about C# and F#

How To Turn Off Framework Tests in a CI Action

My latest project is a Json Serializer/Deserializer (Ferris.Json).

Say I have a classlib that is targeting .netstandard2.0 because I want to support .NetFramework.

So to ensure everything works on framework, my test library is multitargeted:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>net462;net8.0</TargetFrameworks>
    <!-- Other stuff -->
  </PropertyGroup>
</Project>

In visual studio, I can see that tests for both net462 and net8.0:

targetFrameworks

Running locally this works great. I can run each test on both frameworks, and have noticed some differences I wouldn’t expect.

Github Action

The problem arises when I create a github action for my project. Since my test project is multitargeted, it attempts to test on net462.

Since I’m using an ubuntu image, this fails since .NetFramework is Windows only.

To fix that, I had to add the following command line argument in my action yaml file: --framework net8.0

- name: Test
      run: dotnet test --framework net8.0 --no-build --verbosity normal

This tells dotnet to only run the supported framework, net8.0.

Ideally, I could also run the the net462 tests in my CI build, but I don’t want to mess with windows containers.