highbyte / sonarscan-dotnet

GitHub Action SonarCloud/SonarQube scanner for .NET 8/7/6/5 and .NET Core applications with pull request decoration support
https://github.com/marketplace/actions/sonarscan-dotnet
MIT License
36 stars 24 forks source link

Support for multi targets ? #18

Closed aimenux closed 1 year ago

aimenux commented 1 year ago

Hi,

I m trying to use sonarscan-dotnet in a project targetting both .net 6 and .net 7 but i m getting this error :

Testhost process for source(s) '/github/workspace/test/Tests/bin/Debug/net6.0/Tests.dll' exited with error: 
You must install or update .NET to run this application.
App: /github/workspace/test/Tests/bin/Debug/net6.0/testhost.dll
Architecture: x64
Framework: 'Microsoft.NETCore.App', version '6.0.0' (x64)
.NET location: /usr/share/dotnet/
The following frameworks were found:
  5.0.17 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]
  7.0.2 at [/usr/share/dotnet/shared/Microsoft.NETCore.App]

I have 2 jobs in my yaml file :

The job1 is passing without any errors about some missing sdk but the job2 using sonarscan-dotnet is failling.

Do you have any idea please how to fix the issue and enable the scan of a project with multi targets ?

Thanks in advance.

highbyte commented 1 year ago

Hi,

Thanks for reporting an interesting issue.

This GitHub Action is docker-based, and in the latest version uses the Microsoft base image mcr.microsoft.com/dotnet/sdk:7.0 to provide the DotNet SDK.

As you discovered, for some reason the dotnet test command (when used in a container based on that 7.0 image) doesn't seem able to execute tests against a net6.0 target. The dotnet build command (that is issued right before within this action) works fine though for net6.0.

Docker-based Actions are self-contained, and adding "actions/setup-dotnet" in previous workflow steps won't affect the capabilities of this action.

A workaround would be to run the tests only for the net7.0 target by setting -f net7.0 option in the action parameter dotnetTestArguments in your workflow.

The problem (as I understand it) doesn't seem related specifically to multi-targeting, but rather not being able to run net6.0 tests from net7.0 Microsoft Docker base image.

aimenux commented 1 year ago

Thanks @highbyte for your response, I already fixed my pipeline with the -f option.