SonarCloud is taking more time

When we try to build dot net application with sonar cloud it is taking more than 1 hour. Below are the details.

  • ALM used - Azure DevOps
  • CI system used - Azure DevOps
  • Scanner command used when applicable (private details masked)
  • Languages of the repository - C#
  • Error observed - Without sonar cloud the build is taking less time(8 Min) and with sonar cloud build is taking more than 1 hour.

Hey @AshokReddy,

Welcome to the community!

Can you share what is the approximate size of your code base (for e.g it is a big one, with a couple of million lines of code)?

Best,
Marcin

Hi Marcin, We have around 7500 files.

hi @AshokReddy

Did you go through our Troubleshooting .NET performance problems guide?

If yes and you haven’t found a way to optimize the build yourself, please give us the following version information:

  • please give us the verbose output of the scanner commands (please run SonarScanner.MSBuild.exe begin /k:“MyProject” /d:sonar.verbose=true as the begin step, and please attach the output of the BEGIN and END steps)
  • please give the output of running MSBuild in verbose mode (/v:d)

We enabled sonar.verbose=true in the configuration(Azure pipeline). We are not able to see verbose output. May I know where we can find?

Below is the our .Net project structure for your reference.

There are 17 + projects in solution and there are 3-4 project which are kind of common project referred in most of the other projects. Sonar cloud is scanning these common projects multiple times, hence this process is taking more time than required.

Without sonar cloud configuration, it’s taking 10 Minutes. But, with Sonar it’s taking more than 1 hour.


To get the build verbose output, you need to:

Like the Troubleshooting guide says, please run with reportanalyzer:

  • MsBuild.exe /t:Rebuild /p:reportanalyzer=true /v:d
    to the DotNetCoreCLI command. You can read the documentation from Microsoft on how to pass additional parameters to the build command.

I see that you run the build multiple times - please read in the Troubleshooting .NET performance problems guide:

Make sure you do not run the analysis twice

And I see you have multiple DotNetCoreCLI commands - why do you have this?

Thanks for your response.

For your question ‘I see you have multiple DotNetCoreCLI commands - why do you have this?’ - Since we have micro service architecture for each project we are using separate DotNetCoreCLI command.

Can you run the builds in parallel to speed up, or are there dependencies between the builds?

We generated MSBuild logs in local system. Can you please share your email id to send logs to you.

MSBuild_Verbose_Logs.txt (762.6 KB)
Please find the attached MSBuild verbose logs.

It seems that the logs are trimmed.

You can access the private message I’ve sent you on this link https://community.sonarsource.com/t/re-sonarcloud-is-taking-more-time/55021

I was regenerated MSBuild logs again and attached logs in the private message. Can you please check confirm if you received latest log file. I have used below command to generate MSBuild logs.

MsBuild.exe /t:Rebuild /p:reportanalyzer=true /v:d

Hi @AshokReddy. FYI Andrei has received the logs but hasn’t had a chance to look at them yet. He’ll get back to you when he has done so.

Thanks for the Update Duncan.

After running the BEGIN step of the Scanner for .NET / SonarCloudPrepare@1 if you are using AZP , you must run MSBuild as you do, and then send me the logs.

If you’re running from the command line, the console normally has a limited size and it will only output the last few thousands of lines. To store all build logs, you need to redirect the output to a file.

command.exe > output.txt

and then share that file with me

Logs.txt (1.8 KB)
Please find the attached MS Build Sonar logs. I am enabled sonar configuration on Azure pipeline and it’s failing after 1 hour with time out error. Below is the screen shot where it’s failed with time out error. Can you please review it once and guide us how we can reduce the time to below 15 to 30 minutes. Seems each task is taking more than 5 minutes and we have 17+ tasks.

Can you run the tasks in parallel? We support concurrent builds.

All DotNetCoreCLI tasks should depend on “SonarCloudPrepare”, and then all the builds can be done in parallel, and after all the builds finish, run “SonarCloudAnalyze”.

LE: actually I realized that you could only do that on parallel agents so that wouldn’t work.

Hi @AshokReddy ,

We’re not having much luck with the log files: the two you sent Andrei in the private message are truncated and appear to be from builds that didn’t perform a Sonar analysis, and the latest log file in this thread is for the “prepare” step not a build step.

Let’s back up a bit. Your build pipeline has multiple “DotNetCoreCLI” steps. Could you share the commands that are being executed in those steps please?

You can use the same private message that Andrei started to share the logs if you prefer.

Thanks.

I have shared above requested info through private message. Can you please check it once and let me know if you need more details.

@AshokReddy, thanks for that info. From looking at the pipeline definition, I can think of two approaches you could try.

Option 1

  • create a solution that references all of the projects you want to build, and build that solution first
  • add --no-build option to all of the existing dotnet publish steps to the projects from being rebuilt.

This looks pretty close to what you have in the pipeline already, as I see there is solution that is being used for restoring, but the solution build step is commented out.

Option 2

The second option is more complicated and involves adding some logic to the “core” projects so by default they are excluded from analysis;

  • add the following snippet to all of the “common” projects that are being analyzed multiple times:
  <PropertyGroup>
    <!-- Don't analyze this project unless the caller explicitly requests it -->
    <SonarQubeExclude Condition=" $(AnalyzeCommonProjects) == 'true' " >true</SonarQubeExclude>
  </PropertyGroup>
  • in the build pipeline, change the first DotNetCoreCLI@2 step that is building the common projects so that it passes -p:AnalyzeCommonProject=true as an argument to MSBuild.

Of these, option (1) is simpler and should be more efficient.