Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure Scanner runs with .NET 6 SDK #1095

Closed
tom-howlett-sonarsource opened this issue Nov 2, 2021 · 15 comments · Fixed by #1114
Closed

Ensure Scanner runs with .NET 6 SDK #1095

tom-howlett-sonarsource opened this issue Nov 2, 2021 · 15 comments · Fixed by #1114
Assignees
Milestone

Comments

@tom-howlett-sonarsource
Copy link
Contributor

tom-howlett-sonarsource commented Nov 2, 2021

The Scanner currently requires an SDK that matches the major and minor version of the scanner build. We would like to allow users to run the scanner on agents with only .NET 6 SDK to match our policy of allowing the scanner to run where the code is built without additional installs.

The goal of this ticket is to:

  1. Explore ways that single scanner builds could run with mutiple SDKs
  2. If no practical ways are found create a build for .NET 6
@tom-howlett-sonarsource tom-howlett-sonarsource added this to To do in S4NET Kanban via automation Nov 2, 2021
@tom-howlett-sonarsource tom-howlett-sonarsource moved this from To do to In progress in S4NET Kanban Nov 2, 2021
@tom-howlett-sonarsource tom-howlett-sonarsource moved this from In progress to To do in S4NET Kanban Nov 4, 2021
@tom-howlett-sonarsource tom-howlett-sonarsource removed their assignment Nov 4, 2021
@msallin
Copy link

msallin commented Nov 8, 2021

Maybe you just want to create a build for .NET 6 and investigate afterward... This blocks our adoption of .NET 6 :)
You can just specify multiple targets. This is what we do for our global tools.

@tom-howlett-sonarsource
Copy link
Contributor Author

Hi @msallin

Sorry hear that. To help me understand the 'why', can you let me know where your build agent is running? Why would it not be possible or desirable to also have .NET 5 installed?

Thanks

Tom

@msallin
Copy link

msallin commented Nov 8, 2021

We run our builds on Jenkins. For this, we do xcopy "install" of the SDK. And our pipeline is built to be able to just have one SDK. To have multiple, we have to do an xcopy/merge "install" which is pain. Hence, we always just use the latest SDK.
Our own global tools just target multiple frameworks.

@Christian-Oleson
Copy link

Maybe you just want to create a build for .NET 6 and investigate afterward... This blocks our adoption of .NET 6 :) You can just specify multiple targets. This is what we do for our global tools.

Agreed, the sooner we can get a .NET 6 build, the better

@IGx89
Copy link

IGx89 commented Nov 8, 2021

This is the error I get attempting to run a scan on a .NET 6 projects on a GitHub Actions runner (ubuntu-20.04):

It was not possible to find any compatible framework version
The framework 'Microsoft.NETCore.App', version '5.0.0' (x64) was not found.
  - The following frameworks were found:
      6.0.0 at [/home/runner/.dotnet/shared/Microsoft.NETCore.App]

You can resolve the problem by installing the specified framework and/or SDK.

The specified framework can be found at:
  - https://aka.ms/dotnet-core-applaunch?framework=Microsoft.NETCore.App&framework_version=5.0.0&arch=x64&rid=ubuntu.20.04-x64

That's a bit confusing to me, because according to GitHub that runner already has (multiple!) .NET 5 SDKs installed: https://github.com/actions/virtual-environments/blob/main/images/linux/Ubuntu2004-README.md#net-core-sdk

@tom-howlett-sonarsource
Copy link
Contributor Author

Hi @IGx89

Thanks for reporting this. Although the Github Action Runner has multiple SDKs installed, when we include:

- name: Setup .NET 6
        uses: actions/setup-dotnet@v1
        with:
          dotnet-version: 6.0.x

It disables the other .NET versions

We will get a .NET 6 compatible scanner out as soon as we can, in the meantime there is a workaround you can use by switching between .NET 5 & 6 at the appropriate points. I've created an example of this here
``

@duncanp-sonar
Copy link
Contributor

An alternative workaround to try would be to execute the scanner as follows:

dotnet --roll-forward LatestMajor sonarscanner.msbuild.dll ... 

See the MS docs for more information.

@IGx89
Copy link

IGx89 commented Nov 9, 2021

That's a great idea, thanks! Adding the following to the SonarScanner Begin/End steps caused it to work:

        env:
          DOTNET_ROLL_FORWARD: Major

Unfortunately however, it's no longer reporting LOC/issues for a lot of the *.cs files (Blazor webapp). Still better than turning off scanning completely at least.

@andrei-epure-sonarsource
Copy link
Contributor

Unfortunately however, it's no longer reporting LOC/issues for a lot of the *.cs files (Blazor webapp). Still better than turning off scanning completely at least.

Hello @IGx89. Would it be possible to provide a reproducer for this problem?

@IGx89
Copy link

IGx89 commented Nov 22, 2021

Unfortunately however, it's no longer reporting LOC/issues for a lot of the *.cs files (Blazor webapp). Still better than turning off scanning completely at least.

Hello @IGx89. Would it be possible to provide a reproducer for this problem?

You actually sort of already provided one yourself -- just take https://github.com/andrei-epure-sonarsource/aspnet5mvc-reproducer and change the csproj TFM from net5.0 to net6.0. LOC was present for the former but disappeared when I changed to the latter.

@andrei-epure-sonarsource
Copy link
Contributor

Thanks @IGx89 , I confirm the regression on ASP .NET 6 MVC projects. Opened #1116.

PolaEdward added a commit to PolaEdward/estafette-extension-dotnet that referenced this issue Nov 24, 2021
Currently sonarscanner doesn't work if only .net 6.0 is installed.
As suggested in [this](SonarSource/sonar-scanner-msbuild#1095 (comment)) thread, using RollForward flag should fix that issue
@pavel-mikula-sonarsource pavel-mikula-sonarsource moved this from In progress to Review in progress in S4NET Kanban Nov 25, 2021
@balajigv-mcd
Copy link

Does latest version of Sonar Scanner supports .NET6 API projects , In docs it says it supports the .NET6 Web Projects only. if not can i know which version of Sonarscanner supports .NET6 API Projects

@andrei-epure-sonarsource
Copy link
Contributor

@balajigv-mcd we explicitly mention .NET Web Projects because they have a new compilation mechanism for Razor files.

Yes .NET 6 API Projects are supported as well.

(cc @tom-howlett-sonarsource )

@dacardona
Copy link

dacardona commented Apr 17, 2022

Hi. I'm facing same problem with .NET 6 + GitLab CI. + SonarCloud

I'm a bit confused because everyone talk about install SDK or use some version of .net. But when I setted up my account and import the project from my GitLab account the suggested job just call the binary sonar-scanner that's all. We are using the docker image sonarsource/sonar-scanner-cli:latest

Where should I specify the framework version? or where to passing parameters to any dotnet build or dotnet test?

This is my Job which was proposed by SonarCloud wizard:

sonarcloud-sast-qa:
  image:
    name: sonarsource/sonar-scanner-cli:latest
    entrypoint: [""]
  stage: test
  variables:
    SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar"  # Defines the location of the analysis task cache
    GIT_DEPTH: "0"  # Tells git to fetch all the branches of the project, required by the analysis task
  cache:
    key: "${CI_JOB_NAME}"
    paths:
      - .sonar/cache
  script:
    - sonar-scanner

@pavel-mikula-sonarsource
Copy link
Contributor

Hi @dacardona, this repository is not related to sonar-scanner-cli. Please post your question on your https://community.sonarsource.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
S4NET Kanban
  
Done
Development

Successfully merging a pull request may close this issue.

9 participants