SonarCloud Support for .NET Core 3.0.100-preview5

We found a GitHub issue which describe an issue with supporting .NET 3.0 preview and seems to suggest it’s resolved. (https://github.com/SonarSource/sonar-scanner-msbuild/issues/649)

We get the following error when using 1.6.2 of SonarCube Extension for Azure Pipelines

        Task         : Prepare Analysis Configuration
        Description  : Prepare SonarCloud analysis configuration
        Version      : 1.6.2
        Author       : sonarsource
        Help         : [More Information](http://redirect.sonarsource.com/doc/install-configure-scanner-tfs-ts.html)
        ==============================================================================
        SYSTEMVSSCONNECTION exists true
        [command]/opt/hostedtoolcache/dncs/3.0.100-preview5-011568/x64/dotnet /home/vsts/work/_tasks/SonarCloudPrepare_14d9cde6-c1da-4d55-aa01-2965cd301255/1.6.2/dotnet-sonar-scanner-msbuild/SonarScanner.MSBuild.dll begin /k:AAF /o:applicita
        ##[error]It was not possible to find any compatible framework version
        It was not possible to find any compatible framework version
        ##[error]The specified framework 'Microsoft.NETCore.App', version '2.0.0' was not found.
          - The following frameworks were found:
              3.0.0-preview5-27626-15 at [/opt/hostedtoolcache/dncs/3.0.100-preview5-011568/x64/shared/Microsoft.NETCore.App]

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

Is there any support yet for .NET Core 3.0 preview bits ?

Thanks

John

Hi @johnkattenhorn,

Yes, the scanner should work. I think the problem is that the scanner needs a version of the framework that is compatible with 2.0.0 but your build agent only has a preview version of .NET Core 3.0 installed.

If my understanding of the way the .NET runtime binder works is correct then the 3.0-preview isn’t treated as compatible with 2.0.0 because the binder won’t automatically roll-forward to a different major version or from a stable to an unstable preview version (see here).

1 Like

Hey @Duncan,

Thanks for the reply, we added the .NET Core Install task into the build as we use the Microsoft Managed Build Agents but on reading you second paragraph I fear you maybe right and therefore we will be stuck until .NET 3.0 RTM’s.

Can you think of a way to workaround this until then ?

Thanks

John

Which managed agent pool are you using?

Hey @duncanp,

I checked the pool and we were using Ubuntu 16.04 so I switched it to Host and it got much further. It’s now blowing up in some reporting stages but it looks like something related to our yaml configuration.

It’s cheeky but if I posted it would you be able to take a quick look ? I’ve spend an hour or so on it and I can’t see what’s wrong, if I run the commands on my local machine it all seems to work for me but not working on the build server and of course being hosts I can’t just jump on the box :slight_smile:

All the best

John

Sure - post the yaml and the log output containing the errors and I’ll have a look.

This is still an issue but as a workaround you can use the DotNetCoreInstaller task to switch .netcore sdk version as you go through your steps:

steps:    
- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core SDK 2.2.103 For Sonar Cloud'
  inputs:
    version: '2.2.103'

- script: dotnet --list-sdks
  displayName: 'Check dotnet sdks'

- task: SonarCloudPrepare@1
  displayName: 'Prepare SonarCloud analysis'
  inputs:
    SonarCloud: 'SonarCloudConnection'
    organization: '$(organization)'
    projectKey: '$(projectKey)'
    projectName: '$(projectName)'
    projectVersion: '$(Build.BuildNumber)'
    extraProperties: |
     sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/TestResults/Coverage/coverage.opencover.xml

- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core SDK $(dotnetSdkVersion) For Project'
  inputs:
    packageType: sdk
    version: '$(dotnetSdkVersion)'

- script: dotnet --list-sdks
  displayName: 'Check dotnet sdks'

- task: DotNetCoreCLI@2
  displayName: 'Restore Project Dependencies'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'
    feedsToUse: 'select'
    vstsFeed: 'GUID'

- task: DotNetCoreCLI@2
  displayName: 'Build the project - $(buildConfiguration)'
  inputs:
    command: 'build'
    arguments: '--no-restore --configuration $(buildConfiguration)'
    projects: '**/*.csproj'

- task: DotNetCoreCLI@2
  displayName: 'Install ReportGenerator'
  inputs:
    command: custom
    custom: tool
    arguments: 'install --global dotnet-reportgenerator-globaltool'

- task: DotNetCoreCLI@2
  displayName: 'Run unit tests - $(buildConfiguration)'
  inputs:
    command: 'test'
    arguments: '--no-build --configuration $(buildConfiguration) /p:CollectCoverage=true /p:CoverletOutputFormat=cobertura /p:CoverletOutput=$(Build.SourcesDirectory)/TestResults/Coverage/'
    publishTestResults: true
    projects: '**/*.Tests.csproj'

- script: |
    reportgenerator -reports:$(Build.SourcesDirectory)/**/coverage.cobertura.xml -targetdir:$(Build.SourcesDirectory)/CodeCoverage -reporttypes:HtmlInline_AzurePipelines
  displayName: 'Create code coverage report'

- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core SDK 2.2.103 For Sonar Cloud'
  inputs:
    version: '2.2.103'

- script: dotnet --list-sdks
  displayName: 'Check dotnet sdks'

- task: SonarCloudAnalyze@1
  displayName: 'Run SonarCloud code analysis'

- task: SonarCloudPublish@1
  displayName: 'Publish SonarCloud quality gate results'

- task: PublishCodeCoverageResults@1
  displayName: 'Publish code coverage report'
  inputs:
    codeCoverageTool: 'cobertura'
    summaryFileLocation: '$(Build.SourcesDirectory)/**/coverage.cobertura.xml'

Another possible solution is to get multiple DotNet Core sdks installed using the scripts provided by Microsoft here: https://docs.microsoft.com/en-us/dotnet/core/tools/dotnet-install-script

1 Like

Has this already been fixed or do we still need to do the workaround described above?

I ended up changing to a windows-2019 VM and that has what appears to be every dotnet core sdk from 2.1.300 - 3.0.100 currently included automatically.

pool:
  vmImage: 'windows-2019'

Hi,

The dotnet global tool as well as the .NET Core version of the Scanner are both available in .NET core 3, starting version 4.8.0

See the GitHub release : https://github.com/SonarSource/sonar-scanner-msbuild/releases
Or the nuget package for the global tool : https://www.nuget.org/packages/dotnet-sonarscanner/

Mickaël

1 Like