Integrating SonarCloud in alpine dotnet image

I have SonarCloud working fine on Azure Pipelines by using the predefined tasks. I want to move away from this approach, because I want to start building the application in Docker.

Everything was working fine, on a dotnet 6 image running on alpine, until I setup SonarCloud. While running docker build, the begin phase of sonar scanner went well:

SonarScanner for MSBuild 5.10
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
22:46:07.514  Updating build integration targets...
22:46:07.876  Fetching analysis configuration settings...
22:46:08.386  Provisioning analyzer assemblies for cs...
22:46:08.386  Installing required Roslyn analyzers...
22:46:09.244  Provisioning analyzer assemblies for vbnet...
22:46:09.244  Installing required Roslyn analyzers...
22:46:09.286  Pre-processing succeeded.

But then I am getting an error on dotnet build:

/usr/share/dotnet/sdk/6.0.404/Microsoft.Common.CurrentVersion.targets(1220,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at .NET SDKs downloads for Visual Studio [/Portfolio.TimelineCV.Database/Portfolio.TimelineCV.Database.sqlproj]

This is a very strange error… Why would sonar scanner require .Net Framework, when executed on an alpine image? Any ideas on how I can fix this?

This is how I am installing sonar scanner, and setting it up

  apk update && \
  apk add --no-cache openjdk11 && \
  dotnet tool install -g dotnet-sonarscanner && \
  dotnet sonarscanner begin \
    /k:"${SONAR_PROJECT_KEY}" \
    /"${SONAR_HOST_URL}" \
    /d:sonar.login="${SONAR_TOKEN}" \

This is the output of dotnet --version, inside the container:

.NET SDK (reflecting any global.json):
#12 0.299 Version: 6.0.404
#12 0.299 Commit: be4f3ec411
#12 0.299
#12 0.299 Runtime Environment:
#12 0.300 OS Name: alpine
#12 0.300 OS Version: 3.17
#12 0.301 OS Platform: Linux
#12 0.308 RID: alpine.3.17-arm64
#12 0.308 Base Path: /usr/share/dotnet/sdk/6.0.404/
#12 0.309
#12 0.309 global.json file:
#12 0.310 Not found
#12 0.310
#12 0.310 Host:
#12 0.310 Version: 6.0.12
#12 0.310 Architecture: arm64
#12 0.310 Commit: 02e35a40c7
#12 0.310
#12 0.310 .NET SDKs installed:
#12 0.310 6.0.404 [/usr/share/dotnet/sdk]
#12 0.310
#12 0.310 .NET runtimes installed:
#12 0.310 Microsoft.AspNetCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
#12 0.310 Microsoft.NETCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
#12 0.310
#12 0.310 Download .NET:
#12 0.310 .NET Downloads (Linux, macOS, and Windows)
#12 0.310
#12 0.310 Learn about .NET Runtimes and SDKs:
#12 0.310 .NET (and .NET Core) - introduction and overview | Microsoft Learn

Any help would be appreciated!


Why would it not? Per the docs, analysis with the SonarScanner for .NET requires:

  • Java 11 or greater
  • The SDK corresponding to your build system



Thanks for your reply! Let me give you a bit more context into the topic:

  • .NET framework is only available on Windows
  • I’m running the build on an alpine container image (Linux)
  • I’m targeting .NET 6
  • The underlying OS is MacOS, M1 chip

So, Sonar Cloud should not complain about an inexistant .NET Framework. First because the build is happening in a Linux container, and then because I’m targeting a different version of .NET.



How are you building?