Azure Devops .net service build scanning 0 files in Sonar Cloud

Hi,

We are struggling to scan our .net core service and getting 0 lines scanned. Please find my azure devops pipeline yaml below

trigger:
  - $(branch)

pool:
  vmImage: 'ubuntu-latest'

jobs:
  - job: BuildAndAnalyze
    steps:
      - task: UseDotNet@2
        inputs:
          packageType: 'sdk'
          version: '6.x'  # Use the appropriate .NET SDK version
          installationPath: $(Agent.ToolsDirectory)/dotnet

      - task: DotNetCoreCLI@2
        inputs:
          command: 'restore'
          projects: '**/*.sln'
          feedsToUse: 'select'

      - task: SonarCloudPrepare@1
        inputs:
          SonarCloud: 'SonarCloud'
          organization: 'organization-key'
          scannerMode: 'MSBuild'
          projectKey: 'sonar_project-key'

      - task: DotNetCoreCLI@2
        inputs:
          command: 'build'
          projects: '**/*.sln'

      - task: SonarCloudAnalyze@1

      - task: SonarCloudPublish@1

I can see the build get successful and in sonar code analyze shows below message

INFO: Preprocessing files…
INFO: 0 languages detected in 0 preprocessed files
INFO: 0 files ignored because of inclusion/exclusion patterns

Also, in Sonar cloud we can see the scan completed but o lines scanned.

Can you please suggest any change in my yaml or any setting in Sonar cloud to make it working?

Thanks,
Vaibhav

Hi Vaibhav,

Can you please provide full job logs?

Share the Scanner for .NET verbose logs

  • Add /d:"sonar.verbose=true" to the…
    • SonarScanner.MSBuild.exe or dotnet sonarscanner begin command to get more detailed logs
      • For example: SonarScanner.MSBuild.exe begin /k:"MyProject" /d:"sonar.verbose=true"
    • “SonarQubePrepare” or “SonarCloudPrepare” task’s extraProperties argument if you are using Azure DevOps
      • For example:
        - task: SonarCloudPrepare@1
            inputs:
              SonarCloud: 'sonarcloud'
              organization: 'foo'
              scannerMode: 'MSBuild'
              projectKey: 'foo_sonar-scanning-someconsoleapp'
              projectName: 'sonar-scanning-someconsoleapp'
              extraProperties: |
                sonar.verbose=true
        
  • The important logs are in the END step (i.e. SonarQubeAnalyze / SonarCloudAnalyze / “Run Code Analysis”)

Share the msbuild detailed logs

MsBuild.exe /t:Rebuild /v:d

or

dotnet build -v:d

 
Thx,
Ann

Hi Ann,

Thanks for looking into this.

Please find the logs attached.

Thanks,

Vaibhav

ServiceBuildSteps.zip (79.6 KB)

Hi Vaibhav,

Thanks for the logs! I notice two things. First, the “build” log is awfully short. Did anything actually get built here? Because a full build is required for analysis.

Second is this:

2024-03-19T11:17:59.5362246Z ==============================================================================
2024-03-19T11:17:59.5362370Z Task         : .NET Core
2024-03-19T11:17:59.5362434Z Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2024-03-19T11:17:59.5362567Z Version      : 2.235.1
2024-03-19T11:17:59.5362628Z Author       : Microsoft Corporation
2024-03-19T11:17:59.5362703Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2024-03-19T11:17:59.5362816Z ==============================================================================
2024-03-19T11:17:59.8653170Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2024-03-19T11:17:59.9263133Z [command]/usr/bin/dotnet build /home/vsts/work/1/s/src/Services/Scorpeo.ApplicationAccessControl/Scorpeo.ApplicationAccessControl.sln -dl:CentralLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.235.1/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/vsts/work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.235.1/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"

It seems that you’re on a pretty old version of the SDK? From the docs, the prerequisites for analysis include:

 
Ann

Hi Ann,

Thanks for investigating the logs.

Yes, I can see the build get succeeded please see the log attached, maybe you have looked at first .net cli log that was to restore package.

Also, my service is in .net 7 not sure what do you mean by old version of the SDK.

Please confirm if I need to make any change in YAML or in Sonar Cloud?

Thanks,

Vaibhav

5_DotNetCoreCLI.txt (25 KB)

Hi,

I’m not sure these are verbose logs. Can you provide verbose logs, as described above, please?

 
Thx,
Ann

Hi Ann,

Not sure what verbose logs you are looking for.

I am running it in azure devops and attached the .net build log from azure devops.

Can you please elaborate what exactly you need?

Thanks,

Vaibhav

Hi Vaibhav,

Did you do this part?

 
Ann

Hi Ann,

Thanks for clarification, I have amended the pipeline and ran it.

Please find the logs attached.

Thanks,

Vaibhav

ServiceBuildSteps.zip (94.5 KB)

Hi,

I’m not sure what happened, but here’s a snippet of what I see in 6_Run Code Analysis.txt

〲㐲〭ⴳ㈲ㅔ㨳㈰ㄺ⸷㔴㌰㘵娷⌠嬣敳瑣潩嵮瑓牡楴杮›畒潃敤䄠慮祬楳൳㈊㈰ⴴ㌰㈭吲㌱〺㨲㜱㐮㌶㜸㘲⁚㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽㴽਍〲㐲〭ⴳ㈲ㅔ㨳㈰ㄺ⸷

 
Ann

Hi Ann,

Not sure what do you mean by this.

I have gone through the “6_Run Code Analysis.txt” but not able to find anything in Japanese as you mentioned.

Can you suggest any step, please?

Thanks,

Vaibhav

Hi Vaibhav,

That’s what I get when I expand the zip. Maybe try re-bundling?

 
Ann

Hi Ann,

I have re-bundled it, please find the attached zip.

Thanks,

Vaibhav

Hi Vaibhav,

Not seeing a new zip…?

 
:smiley:
Ann

Hi Ann,

It is in the attached email, may be due to security in your email account you are not able to see it.

Please download the attached email and then you will find the attached zip in downloaded email.

Thanks,

Vaibhav

Hi Vaibhav,

I don’t see a new zip. If you responded to this thread via email and attached it there, well it must have gotten scraped off somewhere between your email client and this forum. I suggest you log in directly to the forum to re-post.

 
Ann

Hi Ann, Please find the zip attached. Thanks
ServiceBuildSteps.zip (94.5 KB)

Hi,

I’m still getting an unreadable file for step 6.

 
Ann

Hi Ann,

Please find the step 6 logs attached.

Thanks,

Vaibhav

6_Run Code Analysis.txt (118 KB)

Hi,

A small snippet of what I see:

Selection_1674

 
Ann