Failing to analyze c# code


(Lior Tal) #1

I’m trying to set up SonarQube 7.3 to analyze our C# code.

Versions i am using:

  • SonarQube 7.3 (Windows server)
  • SonarQube scanner for MSBuild (Windows Server)

In the scanner log i can see this line:

[18:24:00]W: [Step 4/4] 18:24:00.108 WARN: Analyzer working directory does not exist: ‘D:\BuildAgent\work\Build_android_Unity_2017_4_12.sonarqube\out\2\output-cs’. Analyzer results won’t be loaded from this directory.

That folder doesn’t exist. Not sure why (or what it’s purpose exactly).
Is there anything else i can write here to assist you with diagnosing what’s wrong?

EDIT: Adding the steps i’m using to run analysis

Begin analysis

D:\BuildServerApps\sonar-scanner-msbuild\SonarScanner.MSBuild.exe begin /k:“CM” / /d:sonar.login=“hidden” /d:sonar.verbose=true /v:3.4.1

Call msbuild

msbuild /t:Rebuild %checkout.dir%.sln

End analysis

D:\BuildServerApps\sonar-scanner-msbuild\SonarScanner.MSBuild.exe end /d:sonar.login=“hidden”

(Valeri Hristov) #2

The path is weird, there should be a slash before .sonarqube… Can you share how you execute the analysis and the build steps?

Anyhow, the .sonarqube\out directory is deleted and recreated when you execute SonarScanner.MSBuild.exe begin, the numbered sub-directories are created when each project is starting its compilation. These directories contain the some intermediate files created from the analysis, that are read when you execute SonarScanner.MSBuild.exe end.

The simplest reason for these directories to disappear is if you run two builds in parallel in the same work directory.

(Lior Tal) #4

updated my question with the steps i’m running to execute analysis.

(Lior Tal) #5

any updates? anything that might help ?

(Valeri Hristov) #6

Hi @liortal, would it be possible to send us the full output of both the begin and end steps (please, keep the /d:sonar.verbose=true parameter) as well as the full output of the MSBuild command with /v:diag argument added. Probably the files will become very big, you could zip them and upload them here:

Btw, are you using TFS to build your source?

(Lior Tal) #7

Hi. i just uploaded the log file you requested.

Also, we are not using TFS. we use TeamCity to run these command line steps.

(Valeri Hristov) #8

Hi @liortal, I cannot see your files, can you upload them again? Thanks!

(Lior Tal) #9

i sent it again. can u check please?

(Valeri Hristov) #10

I got it, thanks! I’ll reply when I have more information.

(Valeri Hristov) #11

Hi @liortal, I suspect you have unsupported version of Visual Studio 2015 on this machine. SonarC# requires Visual Studio 2015 Update 3, otherwise it will not work. The following lines are strong evidence that this is the case:

[01:40:10] :	 [Step 3/4] CSC : warning CS8032: An instance of analyzer SonarAnalyzer.Rules.CSharp.ThreadStaticWithInitializer cannot be created from D:\BuildAgent\temp\buildTmp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [D:\BuildAgent\work\Build_android_Unity_2017_4_12\Assembly-CSharp-firstpass.csproj]

(Lior Tal) #12

it requires this version specifically? BTW - when you say SonarC#, do you mean the machine running SonarQube, or the machine running the actual build steps (msbuild) ?

On the machine running MSBuild I have Visual Studio community 2017 installed.

(Valeri Hristov) #13

I am talking about the machine that is running MSBuild. You need to build your project with the MSBuild and the C# compiler that comes from either VS2015 Update 3 or VS2017 (any update).

As far as I can see from the logs, your build is running with MSBuild 14:

[01:40:05] :	 [Step 3/4] C:\Program Files (x86)\MSBuild\14.0\Bin\msbuild.exe /t:Rebuild /v:diag Build_android_Unity_2017_4_12.sln

which comes with VS2015 and probably you don’t have Update 3 installed on that machine. If you switch to the MSBuild 15 (that comes with VS2017), the analysis should be fine.

(Amaury Levé) #14


Just checking in, did you manage to fix your issue?

(Lior Tal) #15

yes, the issue was solved by re-installing the required MSBuild version (i believe it was just part of VS installation).