Search code examples
c#visual-studiogithubgithub-actions

Github action does not find .NET 8 framework for test, but build works


The below workflow fails for the dotnet test step. The build before works, so I am sure the framework is restored.

.NET location: /usr/share/dotnet/
 No frameworks were found.

For testing I have checked the directory, it is there. Also I have tried to set the env var DOTNET_ROOT: /usr/share/dotnet/ explicitly. Another approach to to set the dependencies a 2nd time directly before the test, no success (this was something I have found as potential solution).

 - name: Install dependencies 
   run: dotnet restore

Crosschecked the 2 projects (test/application), the version related parts are identical.

<TargetFramework>net8.0-windows10.0.17763.0</TargetFramework>
<EnableWindowsTargeting>true</EnableWindowsTargeting>
<SupportedOSPlatformVersion>10.0.17763.0</SupportedOSPlatformVersion>

What could the issue be?

name: Build and Test workflow
on: [push, workflow_dispatch]

jobs:
  build:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        dotnet-version: [ '8.x' ]

    steps:
      - uses: actions/checkout@v4
      - name: Setup dotnet ${{ matrix.dotnet-version }}
        uses: actions/setup-dotnet@v3
        with:
          dotnet-version: ${{ matrix.dotnet-version }}

      # You can test your matrix by printing the current dotnet version
      - name: Display dotnet version
        run: dotnet --version
        
      - name: Install dependencies
        run: dotnet restore

      - name: Build
        run: dotnet build

      - name: Show runtime just to check it is there
        run: |
          ls /usr/share/dotnet/

      - name: Test with dotnet, simplified
        # env:
        #   DOTNET_ROOT: /usr/share/dotnet/
        run: dotnet test

      - name: Test with dotnet, the real thing I wish to run
        run: dotnet test --logger trx --results-directory "TestResults-${{ matrix.dotnet-version }}"
      
      - name: Upload dotnet test results
        uses: actions/upload-artifact@v3
        with:
          name: dotnet-results-${{ matrix.dotnet-version }}
          path: TestResults-${{ matrix.dotnet-version }}
          condition: always() # this step will always run, even if the pipeline is cancel

Log (partially) install works

2024-01-16T20:33:04.1767664Z dotnet-install: Attempting to download using aka.ms link https://dotnetcli.azureedge.net/dotnet/Sdk/8.0.101/dotnet-sdk-8.0.101-linux-x64.tar.gz
2024-01-16T20:33:05.4866704Z dotnet-install: Extracting zip from https://dotnetcli.azureedge.net/dotnet/Sdk/8.0.101/dotnet-sdk-8.0.101-linux-x64.tar.gz
2024-01-16T20:33:13.5590230Z dotnet-install: Installed version is 8.0.101
2024-01-16T20:33:13.5694506Z dotnet-install: Adding to current process PATH: `/usr/share/dotnet`. Note: This change will be visible only when sourcing script.
2024-01-16T20:33:13.5696730Z dotnet-install: Note that the script does not resolve dependencies during installation.
2024-01-16T20:33:13.5699287Z dotnet-install: To check the list of dependencies, go to https://learn.microsoft.com/dotnet/core/install, select your operating system and check the "Dependencies" section.
2024-01-16T20:33:13.5767522Z dotnet-install: Installation finished successfully.
2024-01-16T20:33:13.5933149Z ##[group]Run dotnet --version
2024-01-16T20:33:13.7800075Z 8.0.101
....
2024-01-16T20:33:41.3587598Z A total of 1 test files matched the specified pattern.
2024-01-16T20:33:41.5843829Z Testhost process for source(s) '/home/runner/work/Sams/Sams/SamsUnitTests/bin/Debug/net8.0-windows10.0.17763.0/SamsUnitTests.dll' exited with error: You must install or update .NET to run this application.
2024-01-16T20:33:41.5854437Z App: /home/runner/work/Sams/Sams/SamsUnitTests/bin/Debug/net8.0-windows10.0.17763.0/testhost.dll
2024-01-16T20:33:41.5856081Z Architecture: x64
2024-01-16T20:33:41.5857865Z Framework: 'Microsoft.WindowsDesktop.App', version '8.0.0' (x64)
2024-01-16T20:33:41.5858965Z .NET location: /usr/share/dotnet/
2024-01-16T20:33:41.5859546Z No frameworks were found.
2024-01-16T20:33:41.5860117Z Learn more:
2024-01-16T20:33:41.5860840Z https://aka.ms/dotnet/app-launch-failed
2024-01-16T20:33:41.5861495Z To install missing framework, download:
2024-01-16T20:33:41.5863115Z https://aka.ms/dotnet-core-applaunch?framework=Microsoft.WindowsDesktop.App&framework_version=8.0.0&arch=x64&rid=linux-x64&os=ubuntu.22.04
2024-01-16T20:33:41.5864673Z . Please check the diagnostic logs for more information.
2024-01-16T20:33:41.6787535Z Test Run Aborted.

Solution

  • Lex Li (in the comments) has pointed me in the right direction:

    The project targets Windows and requires Windows SDK 10.0 and above to compile. So you cannot use Ubuntu as the environment. The manifest you chose was incorrect from the beginning. Please switch to a Windows environment and try again.

    Using Windows works. I have used <EnableWindowsTargeting>true</EnableWindowsTargeting> and therefor it is possible to compile on ubuntu.

    Furthermore the UNIT tests are not really Windows dependent and would run on ubuntu. But I got a github warning that build and test use different requirements: The issue was resolved by unifying the two project files in VS2022 and github.

    Obviously now the UNIT test is limited running on Windows only. The error message itself is not very clear and I was completely heading in the wrong direction.

    .NET location: /usr/share/dotnet/
     No frameworks were found.
    

    Means cannot run on ubuntu.