SonarScan on C# build inside Docker Containers on Azure DevOps

Must-share information (formatted with Markdown):

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube: 8.5.0.37579
    Scanner: latest tool from NuGet dotnet tool install --global dotnet-sonarscanner
  • what are you trying to achieve
    I would like to build .NET code inside alpine container image, and have sonarscanner scan .NET source-code.
  • what have you tried so far to achieve this
    Installed jre inside microsoft official sdk build image
    Executed sonarscanner and produces result.

To the question,
I am trying to optimize our build pipeline, and in that regard I would like to execute as much as possible inside docker containers so that creating and maintaing Azure DevOps pipelines are easier and more manageable.In this regard sonarscanner for .NET has always been a painpoint for our project, because it dictates how we must structure our pipeline, and we are missing out on parallel processing in DevOps, as we would like to execute tests in parallell on the build, but now it must be sequential.

So my question is as follows, how can we utilize sonarscanner properly when we are trying to build our solution inside containers when we have .NET sourcecode and uses Azure DevOps? Or what is the recommended apporach for using sonarscanner on DevOps to have highly optimized and fast pipelines?

And a second question, why must sonarscanner be used while buildng .NET solutions? I have tried to read the documentation, but cant find a comprehensive reason for why. Does sonarscan leave any trace in the final release build?

Hi Jonas, welcome to the community :slight_smile:

Our dotnet analyzer is a Roslyn Analyzer that is invoked by Roslyn during the compilation. Apart from the additional warnings that are issued, the scan does not impact the final build. You can read more about how this works in The SonarSource guide for investigating the performance of .NET analysis.

Regarding a recommended approach, it’s currently not possible to use parallel processing because of this limitation. We are looking into ways that we can enable tests to be run in parallel, is this something that would help you?

I hope that helps

Tom