Scan C# project on Mac with MSBuild

Hi:
I am trying to set use MSBuild to scan a project following the instructions in https://sonarcloud.io/documentation/analysis/scan/sonarscanner-for-msbuild/

So if we consider the three steps proposed:

1. SonarScanner.MSBuild.exe begin /k:"project-key" /o:"<organization>" /d:sonar.login="<token>" 
2. MSBuild.exe <path to solution.sln> /t:Rebuild
3. SonarScanner.MSBuild.exe end /d:sonar.login="<token>" 

Since I am running this on a Macbook, step number 1 is:
mono <pathToSonarScanner.MSBuild.exe> begin /k:“MyProjectKey” /d:sonar.host.url="" /d:sonar.login=""

And this seems to work. Here is the output:

SonarScanner for MSBuild 4.6.2
Using the .NET Framework version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories…
17:10:39.917 Updating build integration targets…
17:10:39.953 Fetching analysis configuration settings…
17:10:40.519 Provisioning analyzer assemblies for cs…
17:10:40.519 Installing required Roslyn analyzers…
17:10:40.956 Provisioning analyzer assemblies for vbnet…
17:10:40.956 Installing required Roslyn analyzers…
17:10:40.976 Pre-processing succeeded.

When I try to do the second step, which looks like this:

mono <pathToMsBuild.exe> <MySolution.sln> /t:Rebuild

I get the following output:

Unhandled Exception:
System.TypeInitializationException: The type initializer for ‘Microsoft.Internal.Performance.CodeMarkers’ threw an exception. —> System.EntryPointNotFoundException: FindAtom assembly: type: member:(null)
at (wrapper managed-to-native) Microsoft.Internal.Performance.CodeMarkers+NativeMethods.FindAtom(string)
at Microsoft.Internal.Performance.CodeMarkers…ctor () [0x00006] in <61d256b675144ee480c85be193028a64>:0
at Microsoft.Internal.Performance.CodeMarkers…cctor () [0x00000] in <61d256b675144ee480c85be193028a64>:0
— End of inner exception stack trace —
at Microsoft.Build.CommandLine.MSBuildApp.Main () [0x00028] in <61d256b675144ee480c85be193028a64>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for ‘Microsoft.Internal.Performance.CodeMarkers’ threw an exception. —> System.EntryPointNotFoundException: FindAtom assembly: type: member:(null)
at (wrapper managed-to-native) Microsoft.Internal.Performance.CodeMarkers+NativeMethods.FindAtom(string)
at Microsoft.Internal.Performance.CodeMarkers…ctor () [0x00006] in <61d256b675144ee480c85be193028a64>:0
at Microsoft.Internal.Performance.CodeMarkers…cctor () [0x00000] in <61d256b675144ee480c85be193028a64>:0
— End of inner exception stack trace —
at Microsoft.Build.CommandLine.MSBuildApp.Main () [0x00028] in <61d256b675144ee480c85be193028a64>:0

Can anyone help me understand what I am doing wrong?

Thank you in advance for any clues.

Miguel

Hi @miguelvela,

There doesn’t seem to be anything Sonar-specific on the call stack, so let’s start with the obvious: does the MSBuild step work on its own i.e. if you don’t run the scanner begin step first?

Can you use the .NET Core SDK to build your application rather than mono?

Hi @duncanp

Thank you for your reply. I tried to run the rebuild command on its own and I get the same error. I have now installed the Net Core sdk and VS for Mac and using “dotnet build MySolution.sln /t:Rebuild” instead of using mono. I am still getting compilation errors but at least they seem to be more understandable, so I think that my issue has been resolved.

Thanks again

1 Like

Just to clarify for anyone experiencing the same issue: instead of using “dotnet build MySolution.sln /t:Rebuild” I finally made it work using “msbuild /target:Rebuild MySolution.sln”